-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
113 lines (109 loc) · 2.6 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { File } from "./src/file.ts";
import { Dir } from "./src/dir.ts";
import { Shape, __rest } from "./src/Shape.ts";
import { setFs, getFs } from "./src/fs.ts";
import { setPath } from "./src/path.ts";
import type { Stats } from "./src/types.ts";
import { buffer } from "./src/buffer.ts";
import {
addPlugin,
getPluginTrack,
getPluginTrackFormatted,
} from "./src/pluginAdder.ts";
import { Buffer } from "https://x.nest.land/[email protected]/mod.ts";
import { join, parse } from "https://deno.land/[email protected]/path/mod.ts";
import {
appendFileSync,
copyFileSync,
existsSync,
renameSync,
writeFileSync,
chmodSync,
lstatSync,
unlinkSync,
statSync,
mkdirSync,
readdirSync,
rmdirSync,
openSync,
closeSync,
watch,
} from "https://deno.land/[email protected]/node/fs.ts";
setFs({
appendFileSync,
copyFileSync,
existsSync,
renameSync,
writeFileSync(path, data, position, length, offset) {
if (offset || length || position) {
const file = Deno.openSync(path, {
read: true,
write: true,
create: true,
});
if (position !== undefined)
Deno.seekSync(file.rid, position, Deno.SeekMode.Start);
const toWrite = (
typeof data === "string" ? new TextEncoder().encode(data) : data
).slice(offset, !offset || !length ? undefined : offset + length);
file.writeSync(toWrite);
Deno.close(file.rid);
} else {
return writeFileSync(path, data);
}
},
chmodSync,
unlinkSync,
mkdirSync,
readdirSync,
rmdirSync,
watch,
openSync,
closeSync,
lstatSync(path): Stats {
// @ts-ignore
return lstatSync(path);
},
statSync(path): Stats {
// @ts-ignore
return statSync(path);
},
readFileSync(path, position, length) {
if (length || position) {
const file = Deno.openSync(path, { read: true });
const buffer_len =
length !== undefined
? length
: Deno.statSync(path).size - (position || 0);
const buffer = new Uint8Array(buffer_len);
if (position) Deno.seekSync(file.rid, position, Deno.SeekMode.Start);
file.readSync(buffer);
Deno.close(file.rid);
return Buffer.from(buffer);
}
return Buffer.from(Deno.readFileSync(path));
},
mkTempDir() {
return Deno.makeTempDirSync();
},
mkTempFile() {
return Deno.makeTempFileSync();
},
linkSync: Deno.linkSync,
symlinkSync: Deno.symlinkSync,
truncateSync: Deno.truncateSync,
});
setPath({ join, parse });
buffer.setBuffer(Buffer);
export {
File,
Dir,
Shape,
setFs,
getFs,
Buffer,
addPlugin,
getPluginTrack,
getPluginTrackFormatted,
__rest,
};