Leon4gr45 commited on
Commit
5ad498c
·
verified ·
1 Parent(s): c8439d9

Include updated package-lock.json (part 15)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +14 -0
  2. node_modules/bare-events/index.js +378 -0
  3. node_modules/bare-events/lib/errors.js +26 -0
  4. node_modules/bare-events/package.json +63 -0
  5. node_modules/bare-events/web.d.ts +79 -0
  6. node_modules/bare-events/web.js +353 -0
  7. node_modules/bare-fs/CMakeLists.txt +13 -0
  8. node_modules/bare-fs/LICENSE +201 -0
  9. node_modules/bare-fs/README.md +989 -0
  10. node_modules/bare-fs/binding.c +2889 -0
  11. node_modules/bare-fs/binding.js +1 -0
  12. node_modules/bare-fs/index.d.ts +1232 -0
  13. node_modules/bare-fs/index.js +2842 -0
  14. node_modules/bare-fs/lib/constants.d.ts +49 -0
  15. node_modules/bare-fs/lib/constants.js +49 -0
  16. node_modules/bare-fs/lib/errors.d.ts +11 -0
  17. node_modules/bare-fs/lib/errors.js +55 -0
  18. node_modules/bare-fs/package.json +74 -0
  19. node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
  20. node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
  21. node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
  22. node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
  23. node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
  24. node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
  25. node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
  26. node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +3 -0
  27. node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
  28. node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
  29. node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
  30. node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +3 -0
  31. node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +3 -0
  32. node_modules/bare-fs/promises.d.ts +313 -0
  33. node_modules/bare-fs/promises.js +119 -0
  34. node_modules/bare-os/CMakeLists.txt +13 -0
  35. node_modules/bare-os/LICENSE +201 -0
  36. node_modules/bare-os/README.md +252 -0
  37. node_modules/bare-os/binding.c +1538 -0
  38. node_modules/bare-os/binding.js +1 -0
  39. node_modules/bare-os/index.d.ts +150 -0
  40. node_modules/bare-os/index.js +131 -0
  41. node_modules/bare-os/lib/constants.d.ts +7 -0
  42. node_modules/bare-os/lib/constants.js +7 -0
  43. node_modules/bare-os/lib/errors.d.ts +5 -0
  44. node_modules/bare-os/lib/errors.js +22 -0
  45. node_modules/bare-os/package.json +55 -0
  46. node_modules/bare-os/prebuilds/android-arm/bare-os.bare +0 -0
  47. node_modules/bare-os/prebuilds/android-arm64/bare-os.bare +0 -0
  48. node_modules/bare-os/prebuilds/android-ia32/bare-os.bare +0 -0
  49. node_modules/bare-os/prebuilds/android-x64/bare-os.bare +0 -0
  50. node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare +0 -0
.gitattributes CHANGED
@@ -46,3 +46,17 @@ node_modules/@rollup/rollup-linux-x64-musl/rollup.linux-x64-musl.node filter=lfs
46
  node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node filter=lfs diff=lfs merge=lfs -text
47
  node_modules/@swc/core-linux-x64-musl/swc.linux-x64-musl.node filter=lfs diff=lfs merge=lfs -text
48
  node_modules/@trivago/prettier-plugin-sort-imports/.yarn/install-state.gz filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node filter=lfs diff=lfs merge=lfs -text
47
  node_modules/@swc/core-linux-x64-musl/swc.linux-x64-musl.node filter=lfs diff=lfs merge=lfs -text
48
  node_modules/@trivago/prettier-plugin-sort-imports/.yarn/install-state.gz filter=lfs diff=lfs merge=lfs -text
49
+ node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare filter=lfs diff=lfs merge=lfs -text
50
+ node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare filter=lfs diff=lfs merge=lfs -text
51
+ node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare filter=lfs diff=lfs merge=lfs -text
52
+ node_modules/bare-os/prebuilds/win32-arm64/bare-os.bare filter=lfs diff=lfs merge=lfs -text
53
+ node_modules/bare-os/prebuilds/win32-x64/bare-os.bare filter=lfs diff=lfs merge=lfs -text
54
+ node_modules/bare-url/prebuilds/android-arm64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
55
+ node_modules/bare-url/prebuilds/android-x64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
56
+ node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
57
+ node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
58
+ node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare filter=lfs diff=lfs merge=lfs -text
59
+ node_modules/bare-url/prebuilds/linux-x64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
60
+ node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
61
+ node_modules/bare-url/prebuilds/win32-x64/bare-url.bare filter=lfs diff=lfs merge=lfs -text
62
+ node_modules/better-sqlite3/build/Release/better_sqlite3.node filter=lfs diff=lfs merge=lfs -text
node_modules/bare-events/index.js ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const errors = require('./lib/errors')
2
+
3
+ class EventListener {
4
+ constructor() {
5
+ this.list = []
6
+ this.count = 0
7
+ }
8
+
9
+ append(ctx, name, fn, once) {
10
+ this.count++
11
+ ctx.emit('newListener', name, fn) // Emit BEFORE adding
12
+ this.list.push([fn, once])
13
+ }
14
+
15
+ prepend(ctx, name, fn, once) {
16
+ this.count++
17
+ ctx.emit('newListener', name, fn) // Emit BEFORE adding
18
+ this.list.unshift([fn, once])
19
+ }
20
+
21
+ remove(ctx, name, fn) {
22
+ for (let i = 0, n = this.list.length; i < n; i++) {
23
+ const l = this.list[i]
24
+
25
+ if (l[0] === fn) {
26
+ this.list.splice(i, 1)
27
+
28
+ if (this.count === 1) delete ctx._events[name]
29
+
30
+ ctx.emit('removeListener', name, fn) // Emit AFTER removing
31
+
32
+ this.count--
33
+ return
34
+ }
35
+ }
36
+ }
37
+
38
+ removeAll(ctx, name) {
39
+ const list = [...this.list]
40
+ this.list = []
41
+
42
+ if (this.count === list.length) delete ctx._events[name]
43
+
44
+ for (let i = list.length - 1; i >= 0; i--) {
45
+ ctx.emit('removeListener', name, list[i][0]) // Emit AFTER removing
46
+ }
47
+
48
+ this.count -= list.length
49
+ }
50
+
51
+ emit(ctx, name, ...args) {
52
+ const list = [...this.list]
53
+
54
+ for (let i = 0, n = list.length; i < n; i++) {
55
+ const l = list[i]
56
+
57
+ if (l[1] === true) this.remove(ctx, name, l[0])
58
+
59
+ Reflect.apply(l[0], ctx, args)
60
+ }
61
+
62
+ return list.length > 0
63
+ }
64
+ }
65
+
66
+ function appendListener(ctx, name, fn, once) {
67
+ if (ctx._events === undefined) ctx._events = Object.create(null)
68
+ const e = ctx._events[name] || (ctx._events[name] = new EventListener())
69
+ e.append(ctx, name, fn, once)
70
+ return ctx
71
+ }
72
+
73
+ function prependListener(ctx, name, fn, once) {
74
+ if (ctx._events === undefined) ctx._events = Object.create(null)
75
+ const e = ctx._events[name] || (ctx._events[name] = new EventListener())
76
+ e.prepend(ctx, name, fn, once)
77
+ return ctx
78
+ }
79
+
80
+ function removeListener(ctx, name, fn) {
81
+ if (ctx._events === undefined) return ctx
82
+ const e = ctx._events[name]
83
+ if (e !== undefined) e.remove(ctx, name, fn)
84
+ return ctx
85
+ }
86
+
87
+ function throwUnhandledError(...args) {
88
+ let err
89
+
90
+ if (args.length > 0) err = args[0]
91
+
92
+ if (err instanceof Error === false) err = errors.UNHANDLED_ERROR(err)
93
+
94
+ if (Error.captureStackTrace) {
95
+ Error.captureStackTrace(err, exports.prototype.emit)
96
+ }
97
+
98
+ queueMicrotask(() => {
99
+ throw err
100
+ })
101
+ }
102
+
103
+ module.exports = exports = class EventEmitter {
104
+ constructor() {
105
+ this._events = Object.create(null)
106
+ }
107
+
108
+ addListener(name, fn) {
109
+ return appendListener(this, name, fn, false)
110
+ }
111
+
112
+ addOnceListener(name, fn) {
113
+ return appendListener(this, name, fn, true)
114
+ }
115
+
116
+ prependListener(name, fn) {
117
+ return prependListener(this, name, fn, false)
118
+ }
119
+
120
+ prependOnceListener(name, fn) {
121
+ return prependListener(this, name, fn, true)
122
+ }
123
+
124
+ removeListener(name, fn) {
125
+ return removeListener(this, name, fn)
126
+ }
127
+
128
+ on(name, fn) {
129
+ return appendListener(this, name, fn, false)
130
+ }
131
+
132
+ once(name, fn) {
133
+ return appendListener(this, name, fn, true)
134
+ }
135
+
136
+ off(name, fn) {
137
+ return removeListener(this, name, fn)
138
+ }
139
+
140
+ emit(name, ...args) {
141
+ if (name === 'error' && this._events !== undefined && this._events.error === undefined) {
142
+ throwUnhandledError(...args)
143
+ }
144
+
145
+ if (this._events === undefined) return false
146
+ const e = this._events[name]
147
+ return e === undefined ? false : e.emit(this, name, ...args)
148
+ }
149
+
150
+ listeners(name) {
151
+ if (this._events === undefined) return []
152
+ const e = this._events[name]
153
+ return e === undefined ? [] : [...e.list]
154
+ }
155
+
156
+ rawListeners(name) {
157
+ if (this._events === undefined) return []
158
+ const e = this._events[name]
159
+ return e === undefined ? [] : e.list.map((l) => l[0])
160
+ }
161
+
162
+ eventNames() {
163
+ if (this._events === undefined) return []
164
+ return Reflect.ownKeys(this._events)
165
+ }
166
+
167
+ listenerCount(name) {
168
+ if (this._events === undefined) return 0
169
+ const e = this._events[name]
170
+ return e === undefined ? 0 : e.list.length
171
+ }
172
+
173
+ getMaxListeners() {
174
+ return EventEmitter.defaultMaxListeners
175
+ }
176
+
177
+ setMaxListeners(n) {}
178
+
179
+ removeAllListeners(name) {
180
+ if (arguments.length === 0) {
181
+ for (const key of Reflect.ownKeys(this._events)) {
182
+ if (key === 'removeListener') continue
183
+ this.removeAllListeners(key)
184
+ }
185
+ this.removeAllListeners('removeListener')
186
+ } else {
187
+ const e = this._events[name]
188
+ if (e !== undefined) e.removeAll(this, name)
189
+ }
190
+ return this
191
+ }
192
+ }
193
+
194
+ exports.EventEmitter = exports
195
+
196
+ exports.errors = errors
197
+
198
+ exports.defaultMaxListeners = 10
199
+
200
+ exports.on = function on(emitter, name, opts = {}) {
201
+ const { signal } = opts
202
+
203
+ if (signal && signal.aborted) {
204
+ throw errors.OPERATION_ABORTED(signal.reason)
205
+ }
206
+
207
+ let error = null
208
+ let done = false
209
+
210
+ const events = []
211
+ const promises = []
212
+
213
+ if (name !== 'error') emitter.on('error', onerror)
214
+
215
+ if (signal) signal.addEventListener('abort', onabort)
216
+
217
+ emitter.on(name, onevent)
218
+
219
+ return {
220
+ next() {
221
+ if (events.length) {
222
+ return Promise.resolve({ value: events.shift(), done: false })
223
+ }
224
+
225
+ if (error) {
226
+ const err = error
227
+
228
+ error = null
229
+
230
+ return Promise.reject(err)
231
+ }
232
+
233
+ if (done) return onclose()
234
+
235
+ return new Promise((resolve, reject) => promises.push({ resolve, reject }))
236
+ },
237
+
238
+ return() {
239
+ return onclose()
240
+ },
241
+
242
+ throw(err) {
243
+ return onerror(err)
244
+ },
245
+
246
+ [Symbol.asyncIterator]() {
247
+ return this
248
+ }
249
+ }
250
+
251
+ function onevent(...args) {
252
+ if (promises.length) {
253
+ promises.shift().resolve({ value: args, done: false })
254
+ } else {
255
+ events.push(args)
256
+ }
257
+ }
258
+
259
+ function onerror(err) {
260
+ emitter.off(name, onevent).off('error', onerror)
261
+
262
+ if (promises.length) {
263
+ promises.shift().reject(err)
264
+ } else {
265
+ error = err
266
+ }
267
+
268
+ return Promise.resolve({ done: true })
269
+ }
270
+
271
+ function onabort() {
272
+ signal.removeEventListener('abort', onabort)
273
+
274
+ onerror(errors.OPERATION_ABORTED(signal.reason))
275
+ }
276
+
277
+ function onclose() {
278
+ emitter.off(name, onevent)
279
+
280
+ if (name !== 'error') emitter.off('error', onerror)
281
+
282
+ if (signal) signal.removeEventListener('abort', onabort)
283
+
284
+ done = true
285
+
286
+ if (promises.length) promises.shift().resolve({ done: true })
287
+
288
+ return Promise.resolve({ done: true })
289
+ }
290
+ }
291
+
292
+ exports.once = function once(emitter, name, opts = {}) {
293
+ const { signal } = opts
294
+
295
+ if (signal && signal.aborted) {
296
+ return Promise.reject(errors.OPERATION_ABORTED(signal.reason))
297
+ }
298
+
299
+ return new Promise((resolve, reject) => {
300
+ if (name !== 'error') emitter.on('error', onerror)
301
+
302
+ if (signal) signal.addEventListener('abort', onabort)
303
+
304
+ emitter.once(name, onevent)
305
+
306
+ function onevent(...args) {
307
+ if (name !== 'error') emitter.off('error', onerror)
308
+
309
+ if (signal) signal.removeEventListener('abort', onabort)
310
+
311
+ resolve(args)
312
+ }
313
+
314
+ function onerror(err) {
315
+ emitter.off(name, onevent)
316
+
317
+ if (name !== 'error') emitter.off('error', onerror)
318
+
319
+ reject(err)
320
+ }
321
+
322
+ function onabort() {
323
+ signal.removeEventListener('abort', onabort)
324
+
325
+ onerror(errors.OPERATION_ABORTED(signal.reason))
326
+ }
327
+ })
328
+ }
329
+
330
+ exports.forward = function forward(from, to, names, opts = {}) {
331
+ if (typeof names === 'string') names = [names]
332
+
333
+ const { emit = to.emit.bind(to) } = opts
334
+
335
+ const listeners = names.map(
336
+ (name) =>
337
+ function onevent(...args) {
338
+ emit(name, ...args)
339
+ }
340
+ )
341
+
342
+ to.on('newListener', (name) => {
343
+ const i = names.indexOf(name)
344
+
345
+ if (i !== -1 && to.listenerCount(name) === 0) {
346
+ from.on(name, listeners[i])
347
+ }
348
+ }).on('removeListener', (name) => {
349
+ const i = names.indexOf(name)
350
+
351
+ if (i !== -1 && to.listenerCount(name) === 0) {
352
+ from.off(name, listeners[i])
353
+ }
354
+ })
355
+ }
356
+
357
+ exports.listenerCount = function listenerCount(emitter, name) {
358
+ return emitter.listenerCount(name)
359
+ }
360
+
361
+ exports.getMaxListeners = function getMaxListeners(emitter) {
362
+ if (typeof emitter.getMaxListeners === 'function') {
363
+ return emitter.getMaxListeners()
364
+ }
365
+
366
+ return exports.defaultMaxListeners
367
+ }
368
+
369
+ exports.setMaxListeners = function setMaxListeners(n, ...emitters) {
370
+ if (emitters.length === 0) exports.defaultMaxListeners = n
371
+ else {
372
+ for (const emitter of emitters) {
373
+ if (typeof emitter.setMaxListeners === 'function') {
374
+ emitter.setMaxListeners(n)
375
+ }
376
+ }
377
+ }
378
+ }
node_modules/bare-events/lib/errors.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = class EventEmitterError extends Error {
2
+ constructor(msg, code, fn = EventEmitterError, opts) {
3
+ super(`${code}: ${msg}`, opts)
4
+ this.code = code
5
+
6
+ if (Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, fn)
8
+ }
9
+ }
10
+
11
+ get name() {
12
+ return 'EventEmitterError'
13
+ }
14
+
15
+ static OPERATION_ABORTED(cause, msg = 'Operation aborted') {
16
+ return new EventEmitterError(msg, 'OPERATION_ABORTED', EventEmitterError.OPERATION_ABORTED, {
17
+ cause
18
+ })
19
+ }
20
+
21
+ static UNHANDLED_ERROR(cause, msg = 'Unhandled error') {
22
+ return new EventEmitterError(msg, 'UNHANDLED_ERROR', EventEmitterError.UNHANDLED_ERROR, {
23
+ cause
24
+ })
25
+ }
26
+ }
node_modules/bare-events/package.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "bare-events",
3
+ "version": "2.9.1",
4
+ "description": "Event emitters for JavaScript",
5
+ "exports": {
6
+ "./package": "./package.json",
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ },
11
+ "./global": {
12
+ "types": "./global.d.ts",
13
+ "default": "./global.js"
14
+ },
15
+ "./web": {
16
+ "types": "./web.d.ts",
17
+ "default": "./web.js"
18
+ },
19
+ "./errors": "./lib/errors.js"
20
+ },
21
+ "files": [
22
+ "index.js",
23
+ "index.d.ts",
24
+ "global.js",
25
+ "global.d.ts",
26
+ "web.js",
27
+ "web.d.ts",
28
+ "lib"
29
+ ],
30
+ "scripts": {
31
+ "format": "prettier --write . && lunte --fix",
32
+ "lint": "prettier --check . && lunte",
33
+ "test": "npm run test:bare && npm run test:node",
34
+ "test:bare": "brittle-bare --coverage test.js",
35
+ "test:node": "brittle-node --coverage test.js"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/holepunchto/bare-events.git"
40
+ },
41
+ "author": "Holepunch",
42
+ "license": "Apache-2.0",
43
+ "bugs": {
44
+ "url": "https://github.com/holepunchto/bare-events/issues"
45
+ },
46
+ "homepage": "https://github.com/holepunchto/bare-events#readme",
47
+ "devDependencies": {
48
+ "bare-abort-controller": "^1.0.0",
49
+ "brittle": "^3.3.2",
50
+ "lunte": "^1.8.0",
51
+ "prettier": "^3.4.2",
52
+ "prettier-config-holepunch": "^2.0.0",
53
+ "uncaughts": "^1.1.1"
54
+ },
55
+ "peerDependencies": {
56
+ "bare-abort-controller": "*"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "bare-abort-controller": {
60
+ "optional": true
61
+ }
62
+ }
63
+ }
node_modules/bare-events/web.d.ts ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ interface AbortSignal extends EventTarget {}
2
+
3
+ export interface EventOptions {
4
+ bubbles?: boolean
5
+ cancelable?: boolean
6
+ composed?: boolean
7
+ }
8
+
9
+ export interface Event {
10
+ readonly type: string
11
+ readonly target: EventTarget | null
12
+ readonly currentTarget: EventTarget | null
13
+ readonly bubbles: boolean
14
+ readonly cancelable: boolean
15
+ readonly composed: boolean
16
+ readonly defaultPrevented: boolean
17
+ readonly isTrusted: boolean
18
+
19
+ preventDefault(): void
20
+ stopPropagation(): void
21
+ stopImmediatePropagation(): void
22
+ }
23
+
24
+ export class Event {
25
+ constructor(type: string, options?: EventOptions)
26
+ }
27
+
28
+ export interface CustomEventOptions<T = any> extends EventOptions {
29
+ detail?: T
30
+ }
31
+
32
+ export interface CustomEvent<T = any> extends Event {
33
+ readonly detail: T
34
+ }
35
+
36
+ export class CustomEvent<T = any> {
37
+ constructor(type: string, options?: CustomEventOptions<T>)
38
+ }
39
+
40
+ export interface AddEventListenerOptions {
41
+ capture?: boolean
42
+ passive?: boolean
43
+ once?: boolean
44
+ signal?: AbortSignal | null
45
+ }
46
+
47
+ export interface RemoveEventListenerOptions {
48
+ capture?: boolean
49
+ }
50
+
51
+ export interface EventTarget {
52
+ addEventListener(
53
+ type: string,
54
+ callback: EventListener,
55
+ options?: AddEventListenerOptions | boolean
56
+ ): void
57
+
58
+ removeEventListener(
59
+ type: string,
60
+ callback: EventListener,
61
+ options?: RemoveEventListenerOptions | boolean
62
+ ): void
63
+
64
+ dispatchEvent(event: Event): boolean
65
+ }
66
+
67
+ export class EventTarget {
68
+ constructor()
69
+ }
70
+
71
+ export type EventListener = EventCallback | EventHandler
72
+
73
+ export interface EventCallback {
74
+ (event: Event): void
75
+ }
76
+
77
+ export interface EventHandler {
78
+ handleEvent(event: Event): void
79
+ }
node_modules/bare-events/web.js ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Event state
2
+ const BUBBLES = 0x1
3
+ const CANCELABLE = 0x2
4
+ const COMPOSED = 0x4
5
+ const CANCELED = 0x8
6
+ const DISPATCH = 0x10
7
+ const STOP = 0x20
8
+
9
+ // EventTarget state
10
+ const CAPTURE = 0x1
11
+ const PASSIVE = 0x2
12
+ const ONCE = 0x4
13
+ const REMOVED = 0x8
14
+
15
+ // https://dom.spec.whatwg.org/#event
16
+ class Event {
17
+ // https://dom.spec.whatwg.org/#dom-event-event
18
+ constructor(type, options = {}) {
19
+ const { bubbles = false, cancelable = false, composed = false } = options
20
+
21
+ this._type = type
22
+ this._target = null
23
+ this._state = 0
24
+
25
+ if (bubbles) this._state |= BUBBLES
26
+ if (cancelable) this._state |= CANCELABLE
27
+ if (composed) this._state |= COMPOSED
28
+ }
29
+
30
+ // https://dom.spec.whatwg.org/#dom-event-type
31
+ get type() {
32
+ return this._type
33
+ }
34
+
35
+ // https://dom.spec.whatwg.org/#dom-event-target
36
+ get target() {
37
+ return this._target
38
+ }
39
+
40
+ // https://dom.spec.whatwg.org/#dom-event-currenttarget
41
+ get currentTarget() {
42
+ return null
43
+ }
44
+
45
+ // https://dom.spec.whatwg.org/#dom-event-bubbles
46
+ get bubbles() {
47
+ return (this._state & BUBBLES) !== 0
48
+ }
49
+
50
+ // https://dom.spec.whatwg.org/#dom-event-cancelable
51
+ get cancelable() {
52
+ return (this._state & CANCELABLE) !== 0
53
+ }
54
+
55
+ // https://dom.spec.whatwg.org/#dom-event-composed
56
+ get composed() {
57
+ return (this._state & COMPOSED) !== 0
58
+ }
59
+
60
+ // https://dom.spec.whatwg.org/#dom-event-defaultprevented
61
+ get defaultPrevented() {
62
+ return (this._state & CANCELED) !== 0
63
+ }
64
+
65
+ // https://dom.spec.whatwg.org/#dom-event-istrusted
66
+ get isTrusted() {
67
+ return false
68
+ }
69
+
70
+ // https://dom.spec.whatwg.org/#dom-event-preventdefault
71
+ preventDefault() {
72
+ if (this._state & CANCELABLE) this._state |= CANCELED
73
+ }
74
+
75
+ // https://dom.spec.whatwg.org/#dom-event-stoppropagation
76
+ stopPropagation() {}
77
+
78
+ // https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
79
+ stopImmediatePropagation() {
80
+ this._state |= STOP
81
+ }
82
+
83
+ toJSON() {
84
+ return {
85
+ type: this.type,
86
+ target: this.target,
87
+ bubbles: this.bubbles,
88
+ cancelable: this.cancelable,
89
+ composed: this.composed,
90
+ defaultPrevented: this.defaultPrevented,
91
+ isTrusted: this.isTrusted
92
+ }
93
+ }
94
+
95
+ [Symbol.for('bare.inspect')]() {
96
+ return {
97
+ __proto__: { constructor: Event },
98
+
99
+ type: this.type,
100
+ target: this.target,
101
+ bubbles: this.bubbles,
102
+ cancelable: this.cancelable,
103
+ composed: this.composed,
104
+ defaultPrevented: this.defaultPrevented,
105
+ isTrusted: this.isTrusted
106
+ }
107
+ }
108
+ }
109
+
110
+ exports.Event = Event
111
+
112
+ // https://dom.spec.whatwg.org/#customevent
113
+ exports.CustomEvent = class CustomEvent extends Event {
114
+ constructor(type, options = {}) {
115
+ super(type, options)
116
+
117
+ const { detail = null } = options
118
+
119
+ this._detail = detail
120
+ }
121
+
122
+ // https://dom.spec.whatwg.org/#dom-customevent-detail
123
+ get detail() {
124
+ return this._detail
125
+ }
126
+ }
127
+
128
+ // https://dom.spec.whatwg.org/#eventtarget
129
+ exports.EventTarget = class EventTarget {
130
+ // https://dom.spec.whatwg.org/#dom-eventtarget-eventtarget
131
+ constructor() {
132
+ this._listeners = new Map()
133
+ }
134
+
135
+ // https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener
136
+ addEventListener(type, callback = null, options = {}) {
137
+ if (typeof options === 'boolean') options = { capture: options }
138
+
139
+ const { capture = false, passive = false, once = false, signal = null } = options
140
+
141
+ if (signal !== null && signal.aborted) return
142
+ if (callback === null) return
143
+
144
+ const listener = new EventListener(type, callback, capture, passive, once, signal)
145
+
146
+ const listeners = this._listeners.get(type)
147
+
148
+ if (listeners !== undefined) {
149
+ for (const existing of listeners) {
150
+ if (callback === existing.callback && capture === existing.capture) {
151
+ return // Duplicate listener
152
+ }
153
+ }
154
+
155
+ listener.link(listeners)
156
+ } else {
157
+ this._listeners.set(type, listener)
158
+ }
159
+
160
+ if (signal !== null) {
161
+ const self = this
162
+ signal.addEventListener('abort', onabort)
163
+
164
+ function onabort() {
165
+ self._unlink(type, listener)
166
+ }
167
+ }
168
+ }
169
+
170
+ // https://dom.spec.whatwg.org/#dom-eventtarget-removeeventlistener
171
+ removeEventListener(type, callback = null, options = {}) {
172
+ if (typeof options === 'boolean') options = { capture: options }
173
+
174
+ const { capture = false } = options
175
+
176
+ const listeners = this._listeners.get(type)
177
+
178
+ if (listeners === undefined) return
179
+
180
+ for (const existing of listeners) {
181
+ if (callback === existing.callback && capture === existing.capture) {
182
+ this._unlink(type, existing)
183
+ return
184
+ }
185
+ }
186
+ }
187
+
188
+ // https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
189
+ dispatchEvent(event) {
190
+ event._target = this
191
+ event._state |= DISPATCH
192
+
193
+ const listeners = this._listeners.get(event.type)
194
+
195
+ try {
196
+ if (listeners === undefined) return true
197
+
198
+ const snapshot = Array.from(listeners)
199
+
200
+ for (const listener of snapshot) {
201
+ // https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke
202
+
203
+ if (listener.removed) continue
204
+
205
+ if (listener.once) this._unlink(event.type, listener)
206
+
207
+ let callback = listener.callback
208
+ let context = this
209
+
210
+ if (typeof callback === 'object') {
211
+ context = callback
212
+ callback = callback.handleEvent
213
+ }
214
+
215
+ Reflect.apply(callback, context, [event])
216
+
217
+ if (event._state & STOP) break
218
+ }
219
+
220
+ return (event._state & CANCELED) === 0
221
+ } finally {
222
+ event._state &= ~DISPATCH
223
+ event._state &= ~STOP
224
+ }
225
+ }
226
+
227
+ toJSON() {
228
+ return {}
229
+ }
230
+
231
+ [Symbol.for('bare.inspect')]() {
232
+ return {
233
+ __proto__: { constructor: EventTarget }
234
+ }
235
+ }
236
+
237
+ _unlink(type, listener) {
238
+ if (listener.removed) return
239
+
240
+ const head = this._listeners.get(type)
241
+ const next = listener.unlink()
242
+
243
+ if (head === listener) {
244
+ if (next === listener) this._listeners.delete(type)
245
+ else this._listeners.set(type, next)
246
+ }
247
+ }
248
+ }
249
+
250
+ // https://dom.spec.whatwg.org/#concept-event-listener
251
+ class EventListener {
252
+ constructor(type, callback, capture, passive, once, signal) {
253
+ this._type = type
254
+ this._callback = callback
255
+ this._signal = signal
256
+ this._state = 0
257
+
258
+ if (capture) this._state |= CAPTURE
259
+ if (passive) this._state |= PASSIVE
260
+ if (once) this._state |= ONCE
261
+
262
+ this._previous = this
263
+ this._next = this
264
+ }
265
+
266
+ get type() {
267
+ return this._type
268
+ }
269
+
270
+ get callback() {
271
+ return this._callback
272
+ }
273
+
274
+ get capture() {
275
+ return (this._state & CAPTURE) !== 0
276
+ }
277
+
278
+ get passive() {
279
+ return (this._state & PASSIVE) !== 0
280
+ }
281
+
282
+ get once() {
283
+ return (this._state & ONCE) !== 0
284
+ }
285
+
286
+ get removed() {
287
+ return (this._state & REMOVED) !== 0
288
+ }
289
+
290
+ link(listener) {
291
+ const next = this._next
292
+ const previous = listener._previous
293
+
294
+ this._next = listener
295
+ listener._previous = this
296
+
297
+ previous._next = next
298
+ next._previous = previous
299
+
300
+ return listener
301
+ }
302
+
303
+ unlink() {
304
+ if (this.removed) return this
305
+
306
+ this._state |= REMOVED
307
+
308
+ const next = this._next
309
+ const previous = this._previous
310
+
311
+ this._next = this
312
+ this._previous = this
313
+
314
+ previous._next = next
315
+ next._previous = previous
316
+
317
+ return next
318
+ }
319
+
320
+ *[Symbol.iterator]() {
321
+ let current = this
322
+
323
+ while (true) {
324
+ const next = current._next
325
+ yield current
326
+ if (next === this) break
327
+ current = next
328
+ }
329
+ }
330
+
331
+ toJSON() {
332
+ return {
333
+ type: this.type,
334
+ capture: this.capture,
335
+ passive: this.passive,
336
+ once: this.once,
337
+ removed: this.removed
338
+ }
339
+ }
340
+
341
+ [Symbol.for('bare.inspect')]() {
342
+ return {
343
+ __proto__: { constructor: EventListener },
344
+
345
+ type: this.type,
346
+ callback: this.callback,
347
+ capture: this.capture,
348
+ passive: this.passive,
349
+ once: this.once,
350
+ removed: this.removed
351
+ }
352
+ }
353
+ }
node_modules/bare-fs/CMakeLists.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cmake_minimum_required(VERSION 4.0)
2
+
3
+ find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
4
+
5
+ project(bare_fs C)
6
+
7
+ add_bare_module(bare_fs)
8
+
9
+ target_sources(
10
+ ${bare_fs}
11
+ PRIVATE
12
+ binding.c
13
+ )
node_modules/bare-fs/LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
node_modules/bare-fs/README.md ADDED
@@ -0,0 +1,989 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # bare-fs
2
+
3
+ Native file system operations for Bare. The API closely follows that of the Node.js `fs` module.
4
+
5
+ ```
6
+ npm i bare-fs
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```js
12
+ const fs = require('bare-fs')
13
+
14
+ const fd = await fs.open('hello.txt')
15
+
16
+ const buffer = Buffer.alloc(1024)
17
+
18
+ try {
19
+ const length = await fs.read(fd, buffer)
20
+
21
+ console.log('Read', length, 'bytes')
22
+ } finally {
23
+ await fs.close(fd)
24
+ }
25
+ ```
26
+
27
+ ## API
28
+
29
+ #### `const fd = await fs.open(filepath[, flags[, mode]])`
30
+
31
+ Open a file, returning a file descriptor. `flags` defaults to `'r'` and `mode` defaults to `0o666`. `flags` may be a string such as `'r'`, `'w'`, `'a'`, `'r+'`, etc., or a numeric combination of `fs.constants` flags.
32
+
33
+ #### `fs.open(filepath[, flags[, mode]], callback)`
34
+
35
+ Callback version of `fs.open()`.
36
+
37
+ #### `const fd = fs.openSync(filepath[, flags[, mode]])`
38
+
39
+ Synchronous version of `fs.open()`.
40
+
41
+ #### `await fs.close(fd)`
42
+
43
+ Close a file descriptor.
44
+
45
+ #### `fs.close(fd, callback)`
46
+
47
+ Callback version of `fs.close()`.
48
+
49
+ #### `fs.closeSync(fd)`
50
+
51
+ Synchronous version of `fs.close()`.
52
+
53
+ #### `await fs.access(filepath[, mode])`
54
+
55
+ Check whether the file at `filepath` is accessible. `mode` defaults to `fs.constants.F_OK`.
56
+
57
+ #### `fs.access(filepath[, mode], callback)`
58
+
59
+ Callback version of `fs.access()`.
60
+
61
+ #### `fs.accessSync(filepath[, mode])`
62
+
63
+ Synchronous version of `fs.access()`.
64
+
65
+ #### `const exists = await fs.exists(filepath)`
66
+
67
+ Check whether a file exists at `filepath`. Returns `true` if the file is accessible, `false` otherwise.
68
+
69
+ #### `fs.exists(filepath, callback)`
70
+
71
+ Callback version of `fs.exists()`.
72
+
73
+ #### `const exists = fs.existsSync(filepath)`
74
+
75
+ Synchronous version of `fs.exists()`.
76
+
77
+ #### `const bytesRead = await fs.read(fd, buffer[, offset[, len[, pos]]])`
78
+
79
+ Read from a file descriptor into `buffer`. `offset` defaults to `0`, `len` defaults to `buffer.byteLength - offset`, and `pos` defaults to `-1` (current position). Returns the number of bytes read.
80
+
81
+ #### `fs.read(fd, buffer[, offset[, len[, pos]]], callback)`
82
+
83
+ Callback version of `fs.read()`.
84
+
85
+ #### `const bytesRead = fs.readSync(fd, buffer[, offset[, len[, pos]]])`
86
+
87
+ Synchronous version of `fs.read()`.
88
+
89
+ #### `const bytesRead = await fs.readv(fd, buffers[, pos])`
90
+
91
+ Read from a file descriptor into an array of `buffers`. `pos` defaults to `-1`.
92
+
93
+ #### `fs.readv(fd, buffers[, pos], callback)`
94
+
95
+ Callback version of `fs.readv()`.
96
+
97
+ #### `const bytesRead = fs.readvSync(fd, buffers[, pos])`
98
+
99
+ Synchronous version of `fs.readv()`.
100
+
101
+ #### `const bytesWritten = await fs.write(fd, data[, offset[, len[, pos]]])`
102
+
103
+ Write `data` to a file descriptor. When `data` is a string, the signature is `fs.write(fd, data[, pos[, encoding]])` where `encoding` defaults to `'utf8'`. Returns the number of bytes written.
104
+
105
+ #### `fs.write(fd, data[, offset[, len[, pos]]], callback)`
106
+
107
+ Callback version of `fs.write()`.
108
+
109
+ #### `const bytesWritten = fs.writeSync(fd, data[, offset[, len[, pos]]])`
110
+
111
+ Synchronous version of `fs.write()`.
112
+
113
+ #### `const bytesWritten = await fs.writev(fd, buffers[, pos])`
114
+
115
+ Write an array of `buffers` to a file descriptor. `pos` defaults to `-1`.
116
+
117
+ #### `fs.writev(fd, buffers[, pos], callback)`
118
+
119
+ Callback version of `fs.writev()`.
120
+
121
+ #### `const bytesWritten = fs.writevSync(fd, buffers[, pos])`
122
+
123
+ Synchronous version of `fs.writev()`.
124
+
125
+ #### `const stats = await fs.stat(filepath)`
126
+
127
+ Get the status of a file. Returns a `Stats` object.
128
+
129
+ #### `fs.stat(filepath, callback)`
130
+
131
+ Callback version of `fs.stat()`.
132
+
133
+ #### `const stats = fs.statSync(filepath)`
134
+
135
+ Synchronous version of `fs.stat()`.
136
+
137
+ #### `const stats = await fs.lstat(filepath)`
138
+
139
+ Like `fs.stat()`, but if `filepath` is a symbolic link, the link itself is statted, not the file it refers to.
140
+
141
+ #### `fs.lstat(filepath, callback)`
142
+
143
+ Callback version of `fs.lstat()`.
144
+
145
+ #### `const stats = fs.lstatSync(filepath)`
146
+
147
+ Synchronous version of `fs.lstat()`.
148
+
149
+ #### `const stats = await fs.fstat(fd)`
150
+
151
+ Get the status of a file by its file descriptor. Returns a `Stats` object.
152
+
153
+ #### `fs.fstat(fd, callback)`
154
+
155
+ Callback version of `fs.fstat()`.
156
+
157
+ #### `const stats = fs.fstatSync(fd)`
158
+
159
+ Synchronous version of `fs.fstat()`.
160
+
161
+ #### `const stats = await fs.statfs(filepath)`
162
+
163
+ Get filesystem statistics. Returns a `StatFs` object.
164
+
165
+ #### `fs.statfs(filepath, callback)`
166
+
167
+ Callback version of `fs.statfs()`.
168
+
169
+ #### `const stats = fs.statfsSync(filepath)`
170
+
171
+ Synchronous version of `fs.statfs()`.
172
+
173
+ #### `await fs.ftruncate(fd[, len])`
174
+
175
+ Truncate a file to `len` bytes. `len` defaults to `0`.
176
+
177
+ #### `fs.ftruncate(fd[, len], callback)`
178
+
179
+ Callback version of `fs.ftruncate()`.
180
+
181
+ #### `fs.ftruncateSync(fd[, len])`
182
+
183
+ Synchronous version of `fs.ftruncate()`.
184
+
185
+ #### `await fs.chmod(filepath, mode)`
186
+
187
+ Change the permissions of a file. `mode` may be a numeric mode or a string that will be parsed as octal.
188
+
189
+ #### `fs.chmod(filepath, mode, callback)`
190
+
191
+ Callback version of `fs.chmod()`.
192
+
193
+ #### `fs.chmodSync(filepath, mode)`
194
+
195
+ Synchronous version of `fs.chmod()`.
196
+
197
+ #### `await fs.fchmod(fd, mode)`
198
+
199
+ Change the permissions of a file by its file descriptor.
200
+
201
+ #### `fs.fchmod(fd, mode, callback)`
202
+
203
+ Callback version of `fs.fchmod()`.
204
+
205
+ #### `fs.fchmodSync(fd, mode)`
206
+
207
+ Synchronous version of `fs.fchmod()`.
208
+
209
+ #### `await fs.chown(filepath, uid, gid)`
210
+
211
+ Change the owner and group of a file.
212
+
213
+ **NOTE**: The `chown` functions are not implemented on Windows.
214
+
215
+ #### `fs.chown(filepath, uid, gid, callback)`
216
+
217
+ Callback version of `fs.chown()`.
218
+
219
+ #### `await fs.chownSync(filepath, uid, gid)`
220
+
221
+ Synchronous version of `fs.chown()`.
222
+
223
+ #### `await fs.lchown(filepath, uid, gid)`
224
+
225
+ Change the owner and group of a file, but if `filepath` is a symbolic link, the changes are applied only to the link, not the file it refers to.
226
+
227
+ #### `fs.lchown(filepath, uid, gid, callback)`
228
+
229
+ Callback version of `fs.lchown()`.
230
+
231
+ #### `fs.lchownSync(filepath, uid, gid)`
232
+
233
+ Synchronous version of `fs.lchown()`.
234
+
235
+ #### `await fs.fchown(filepath, uid, gid)`
236
+
237
+ Change the owner and group of a file by its file descriptor.
238
+
239
+ #### `fs.fchown(filepath, uid, gid, callback)`
240
+
241
+ Callback version of `fs.fchown()`.
242
+
243
+ #### `fs.fchownSync(filepath, uid, gid)`
244
+
245
+ Synchronous version of `fs.fchown()`.
246
+
247
+ #### `await fs.utimes(filepath, atime, mtime)`
248
+
249
+ Change the access and modification times of a file. Times may be numbers (seconds since epoch) or `Date` objects.
250
+
251
+ #### `fs.utimes(filepath, atime, mtime, callback)`
252
+
253
+ Callback version of `fs.utimes()`.
254
+
255
+ #### `fs.utimesSync(filepath, atime, mtime)`
256
+
257
+ Synchronous version of `fs.utimes()`.
258
+
259
+ #### `await fs.lutimes(filepath, atime, mtime)`
260
+
261
+ Like `fs.utimes()`, but if `filepath` is a symbolic link, the timestamps of the link is changed, not the file it refers to.
262
+
263
+ #### `fs.lutimes(filepath, atime, mtime, callback)`
264
+
265
+ Callback version of `fs.lutimes()`.
266
+
267
+ #### `fs.lutimesSync(filepath, atime, mtime)`
268
+
269
+ Synchronous version of `fs.lutimes()`.
270
+
271
+ #### `await fs.futimes(fd, atime, mtime)`
272
+
273
+ Change the access and modification times of a file by its file descriptor. Times may be numbers (seconds since epoch) or `Date` objects.
274
+
275
+ #### `fs.futimes(fd, atime, mtime, callback)`
276
+
277
+ Callback version of `fs.futimes()`.
278
+
279
+ #### `fs.futimesSync(fd, atime, mtime)`
280
+
281
+ Synchronous version of `fs.futimes()`.
282
+
283
+ #### `await fs.link(src, dst)`
284
+
285
+ Creates a new link (also known as a hard link) to an existing file.
286
+
287
+ #### `fs.link(src, dst, callback)`
288
+
289
+ Callback version of `fs.link()`.
290
+
291
+ #### `fs.linkSync(src, dst)`
292
+
293
+ Synchronous version of `fs.link()`.
294
+
295
+ #### `await fs.mkdir(filepath[, opts])`
296
+
297
+ Create a directory at `filepath`.
298
+
299
+ Options include:
300
+
301
+ ```js
302
+ options = {
303
+ mode: 0o777,
304
+ recursive: false
305
+ }
306
+ ```
307
+
308
+ If `opts` is a number, it is treated as the `mode`. When `recursive` is `true`, parent directories are created as needed.
309
+
310
+ #### `fs.mkdir(filepath[, opts], callback)`
311
+
312
+ Callback version of `fs.mkdir()`.
313
+
314
+ #### `fs.mkdirSync(filepath[, opts])`
315
+
316
+ Synchronous version of `fs.mkdir()`.
317
+
318
+ #### `const path = await fs.mkdtemp(prefix)`
319
+
320
+ Create a unique temporary directory.
321
+
322
+ #### `fs.mkdtemp(prefix, callback)`
323
+
324
+ Callback version of `fs.mkdtemp()`.
325
+
326
+ #### `const path = fs.mkdtempSync(prefix)`
327
+
328
+ Synchronous version of `fs.mkdtemp()`.
329
+
330
+ #### `await fs.rmdir(filepath)`
331
+
332
+ Remove an empty directory.
333
+
334
+ #### `fs.rmdir(filepath, callback)`
335
+
336
+ Callback version of `fs.rmdir()`.
337
+
338
+ #### `fs.rmdirSync(filepath)`
339
+
340
+ Synchronous version of `fs.rmdir()`.
341
+
342
+ #### `await fs.rm(filepath[, opts])`
343
+
344
+ Remove a file or directory at `filepath`.
345
+
346
+ Options include:
347
+
348
+ ```js
349
+ options = {
350
+ force: false,
351
+ recursive: false
352
+ }
353
+ ```
354
+
355
+ When `recursive` is `true`, directories are removed along with their contents. When `force` is `true`, no error is thrown if `filepath` does not exist.
356
+
357
+ #### `fs.rm(filepath[, opts], callback)`
358
+
359
+ Callback version of `fs.rm()`.
360
+
361
+ #### `fs.rmSync(filepath[, opts])`
362
+
363
+ Synchronous version of `fs.rm()`.
364
+
365
+ #### `await fs.unlink(filepath)`
366
+
367
+ Remove a file.
368
+
369
+ #### `fs.unlink(filepath, callback)`
370
+
371
+ Callback version of `fs.unlink()`.
372
+
373
+ #### `fs.unlinkSync(filepath)`
374
+
375
+ Synchronous version of `fs.unlink()`.
376
+
377
+ #### `await fs.rename(src, dst)`
378
+
379
+ Rename a file from `src` to `dst`.
380
+
381
+ #### `fs.rename(src, dst, callback)`
382
+
383
+ Callback version of `fs.rename()`.
384
+
385
+ #### `fs.renameSync(src, dst)`
386
+
387
+ Synchronous version of `fs.rename()`.
388
+
389
+ #### `await fs.copyFile(src, dst[, mode])`
390
+
391
+ Copy a file from `src` to `dst`. `mode` is an optional bitmask created from `fs.constants.COPYFILE_EXCL`, `fs.constants.COPYFILE_FICLONE`, or `fs.constants.COPYFILE_FICLONE_FORCE`.
392
+
393
+ #### `fs.copyFile(src, dst[, mode], callback)`
394
+
395
+ Callback version of `fs.copyFile()`.
396
+
397
+ #### `fs.copyFileSync(src, dst[, mode])`
398
+
399
+ Synchronous version of `fs.copyFile()`.
400
+
401
+ #### `await fs.cp(src, dst[, opts])`
402
+
403
+ Copy a file or directory from `src` to `dst`.
404
+
405
+ Options include:
406
+
407
+ ```js
408
+ options = {
409
+ recursive: false
410
+ }
411
+ ```
412
+
413
+ Set `recursive` to `true` to copy directories and their contents. Files are copied preserving their permissions.
414
+
415
+ #### `fs.cp(src, dst[, opts], callback)`
416
+
417
+ Callback version of `fs.cp()`.
418
+
419
+ #### `fs.cpSync(src, dst[, opts])`
420
+
421
+ Synchronous version of `fs.cp()`.
422
+
423
+ #### `const resolved = await fs.realpath(filepath[, opts])`
424
+
425
+ Resolve the real path of `filepath`, expanding all symbolic links.
426
+
427
+ Options include:
428
+
429
+ ```js
430
+ options = {
431
+ encoding: 'utf8'
432
+ }
433
+ ```
434
+
435
+ Set `encoding` to `'buffer'` to receive the result as a `Buffer`.
436
+
437
+ #### `fs.realpath(filepath[, opts], callback)`
438
+
439
+ Callback version of `fs.realpath()`.
440
+
441
+ #### `const resolved = fs.realpathSync(filepath[, opts])`
442
+
443
+ Synchronous version of `fs.realpath()`.
444
+
445
+ #### `const target = await fs.readlink(filepath[, opts])`
446
+
447
+ Read the target of a symbolic link.
448
+
449
+ Options include:
450
+
451
+ ```js
452
+ options = {
453
+ encoding: 'utf8'
454
+ }
455
+ ```
456
+
457
+ #### `fs.readlink(filepath[, opts], callback)`
458
+
459
+ Callback version of `fs.readlink()`.
460
+
461
+ #### `const target = fs.readlinkSync(filepath[, opts])`
462
+
463
+ Synchronous version of `fs.readlink()`.
464
+
465
+ #### `await fs.truncate(filename[, len])`
466
+
467
+ Truncate the file at `filename` to `len` bytes. `len` defaults to `0`.
468
+
469
+ #### `fs.truncate(filename[, len], callback)`
470
+
471
+ Callback version of `fs.truncate()`.
472
+
473
+ #### `fs.truncateSync(filename[, len])`
474
+
475
+ Synchronous version of `fs.truncate()`.
476
+
477
+ #### `await fs.symlink(target, filepath[, type])`
478
+
479
+ Create a symbolic link at `filepath` pointing to `target`. `type` may be `'file'`, `'dir'`, or `'junction'` (Windows only) or a numeric flag. On Windows, if `type` is not provided, it is inferred from the target.
480
+
481
+ #### `fs.symlink(target, filepath[, type], callback)`
482
+
483
+ Callback version of `fs.symlink()`.
484
+
485
+ #### `fs.symlinkSync(target, filepath[, type])`
486
+
487
+ Synchronous version of `fs.symlink()`.
488
+
489
+ #### `await fs.fsync(fd)`
490
+
491
+ Flush all modified in-core data of the file referred by its file descriptor to the disk device.
492
+
493
+ #### `fs.fsync(fs, callback)`
494
+
495
+ Callback version of `fs.fsync()`.
496
+
497
+ #### `fs.fsyncSync(fd)`
498
+
499
+ Synchronous version of `fs.fsync()`.
500
+
501
+ #### `await fs.fdatasync(fd)`
502
+
503
+ Similar to `fsync`, but does not flush modified metadata unless necessary.
504
+
505
+ #### `fs.fdatasync(fs, callback)`
506
+
507
+ Callback version of `fs.fdatasync()`.
508
+
509
+ #### `fs.fdatasyncSync(fd)`
510
+
511
+ Synchronous version of `fs.fdatasync()`.
512
+
513
+ #### `const dir = await fs.opendir(filepath[, opts])`
514
+
515
+ Open a directory for iteration. Returns a `Dir` object.
516
+
517
+ Options include:
518
+
519
+ ```js
520
+ options = {
521
+ encoding: 'utf8',
522
+ bufferSize: 32
523
+ }
524
+ ```
525
+
526
+ #### `fs.opendir(filepath[, opts], callback)`
527
+
528
+ Callback version of `fs.opendir()`.
529
+
530
+ #### `const dir = fs.opendirSync(filepath[, opts])`
531
+
532
+ Synchronous version of `fs.opendir()`.
533
+
534
+ #### `const entries = await fs.readdir(filepath[, opts])`
535
+
536
+ Read the contents of a directory. Returns an array of filenames or, if `withFileTypes` is `true`, an array of `Dirent` objects.
537
+
538
+ Options include:
539
+
540
+ ```js
541
+ options = {
542
+ encoding: 'utf8',
543
+ withFileTypes: false,
544
+ recursive: false
545
+ }
546
+ ```
547
+
548
+ #### `fs.readdir(filepath[, opts], callback)`
549
+
550
+ Callback version of `fs.readdir()`.
551
+
552
+ #### `const entries = fs.readdirSync(filepath[, opts])`
553
+
554
+ Synchronous version of `fs.readdir()`.
555
+
556
+ #### `const data = await fs.readFile(filepath[, opts])`
557
+
558
+ Read the entire contents of a file. Returns a `Buffer` by default, or a string if an `encoding` is specified.
559
+
560
+ Options include:
561
+
562
+ ```js
563
+ options = {
564
+ encoding: 'buffer',
565
+ flag: 'r'
566
+ }
567
+ ```
568
+
569
+ #### `fs.readFile(filepath[, opts], callback)`
570
+
571
+ Callback version of `fs.readFile()`.
572
+
573
+ #### `const data = fs.readFileSync(filepath[, opts])`
574
+
575
+ Synchronous version of `fs.readFile()`.
576
+
577
+ #### `await fs.writeFile(filepath, data[, opts])`
578
+
579
+ Write `data` to a file, replacing it if it already exists.
580
+
581
+ Options include:
582
+
583
+ ```js
584
+ options = {
585
+ encoding: 'utf8',
586
+ flag: 'w',
587
+ mode: 0o666
588
+ }
589
+ ```
590
+
591
+ #### `fs.writeFile(filepath, data[, opts], callback)`
592
+
593
+ Callback version of `fs.writeFile()`.
594
+
595
+ #### `fs.writeFileSync(filepath, data[, opts])`
596
+
597
+ Synchronous version of `fs.writeFile()`.
598
+
599
+ #### `await fs.appendFile(filepath, data[, opts])`
600
+
601
+ Append `data` to a file, creating it if it does not exist. Accepts the same options as `fs.writeFile()` but defaults to the `'a'` flag.
602
+
603
+ #### `fs.appendFile(filepath, data[, opts], callback)`
604
+
605
+ Callback version of `fs.appendFile()`.
606
+
607
+ #### `fs.appendFileSync(filepath, data[, opts])`
608
+
609
+ Synchronous version of `fs.appendFile()`.
610
+
611
+ #### `const watcher = fs.watch(filepath[, opts], callback)`
612
+
613
+ Watch a file or directory for changes. Returns a `Watcher` object. The `callback`, if provided, is called with `(eventType, filename)` on each change.
614
+
615
+ Options include:
616
+
617
+ ```js
618
+ options = {
619
+ persistent: true,
620
+ recursive: false,
621
+ encoding: 'utf8'
622
+ }
623
+ ```
624
+
625
+ #### `const stream = fs.createReadStream(path[, opts])`
626
+
627
+ Create a readable stream for a file. Returns a `ReadStream`.
628
+
629
+ Options include:
630
+
631
+ ```js
632
+ options = {
633
+ fd: -1,
634
+ flags: 'r',
635
+ mode: 0o666,
636
+ start: 0,
637
+ end: Infinity
638
+ }
639
+ ```
640
+
641
+ If `fd` is provided, `path` may be `null` and the stream reads from the given file descriptor.
642
+
643
+ #### `const stream = fs.createWriteStream(path[, opts])`
644
+
645
+ Create a writable stream for a file. Returns a `WriteStream`.
646
+
647
+ Options include:
648
+
649
+ ```js
650
+ options = {
651
+ fd: -1,
652
+ flags: 'w',
653
+ mode: 0o666
654
+ }
655
+ ```
656
+
657
+ If `fd` is provided, `path` may be `null` and the stream writes to the given file descriptor.
658
+
659
+ #### `fs.constants`
660
+
661
+ An object containing file system constants. See `fs/constants` for the full list. Commonly used constants include:
662
+
663
+ - `fs.constants.O_RDONLY`, `fs.constants.O_WRONLY`, `fs.constants.O_RDWR` — file access flags
664
+ - `fs.constants.O_CREAT`, `fs.constants.O_TRUNC`, `fs.constants.O_APPEND` — file creation flags
665
+ - `fs.constants.F_OK`, `fs.constants.R_OK`, `fs.constants.W_OK`, `fs.constants.X_OK` — file accessibility flags
666
+ - `fs.constants.S_IFMT`, `fs.constants.S_IFREG`, `fs.constants.S_IFDIR`, `fs.constants.S_IFLNK` — file type flags
667
+ - `fs.constants.COPYFILE_EXCL`, `fs.constants.COPYFILE_FICLONE`, `fs.constants.COPYFILE_FICLONE_FORCE` — copy flags
668
+
669
+ ### `Stats`
670
+
671
+ Returned by `fs.stat()`, `fs.lstat()`, and `fs.fstat()`.
672
+
673
+ #### `stats.dev`
674
+
675
+ The device identifier.
676
+
677
+ #### `stats.mode`
678
+
679
+ The file mode (type and permissions).
680
+
681
+ #### `stats.nlink`
682
+
683
+ The number of hard links.
684
+
685
+ #### `stats.uid`
686
+
687
+ The user identifier of the file owner.
688
+
689
+ #### `stats.gid`
690
+
691
+ The group identifier of the file owner.
692
+
693
+ #### `stats.rdev`
694
+
695
+ The device identifier for special files.
696
+
697
+ #### `stats.blksize`
698
+
699
+ The file system block size for I/O operations.
700
+
701
+ #### `stats.ino`
702
+
703
+ The inode number.
704
+
705
+ #### `stats.size`
706
+
707
+ The size of the file in bytes.
708
+
709
+ #### `stats.blocks`
710
+
711
+ The number of 512-byte blocks allocated.
712
+
713
+ #### `stats.atimeMs`
714
+
715
+ The access time in milliseconds since the epoch.
716
+
717
+ #### `stats.mtimeMs`
718
+
719
+ The modification time in milliseconds since the epoch.
720
+
721
+ #### `stats.ctimeMs`
722
+
723
+ The change time in milliseconds since the epoch.
724
+
725
+ #### `stats.birthtimeMs`
726
+
727
+ The creation time in milliseconds since the epoch.
728
+
729
+ #### `stats.atime`
730
+
731
+ The access time as a `Date` object.
732
+
733
+ #### `stats.mtime`
734
+
735
+ The modification time as a `Date` object.
736
+
737
+ #### `stats.ctime`
738
+
739
+ The change time as a `Date` object.
740
+
741
+ #### `stats.birthtime`
742
+
743
+ The creation time as a `Date` object.
744
+
745
+ #### `stats.isDirectory()`
746
+
747
+ Returns `true` if the file is a directory.
748
+
749
+ #### `stats.isFile()`
750
+
751
+ Returns `true` if the file is a regular file.
752
+
753
+ #### `stats.isBlockDevice()`
754
+
755
+ Returns `true` if the file is a block device.
756
+
757
+ #### `stats.isCharacterDevice()`
758
+
759
+ Returns `true` if the file is a character device.
760
+
761
+ #### `stats.isFIFO()`
762
+
763
+ Returns `true` if the file is a FIFO (named pipe).
764
+
765
+ #### `stats.isSymbolicLink()`
766
+
767
+ Returns `true` if the file is a symbolic link. Only meaningful when using `fs.lstat()`.
768
+
769
+ #### `stats.isSocket()`
770
+
771
+ Returns `true` if the file is a socket.
772
+
773
+ ### `Dir`
774
+
775
+ Returned by `fs.opendir()`. Supports both synchronous and asynchronous iteration.
776
+
777
+ #### `dir.path`
778
+
779
+ The path of the directory.
780
+
781
+ #### `const dirent = await dir.read()`
782
+
783
+ Read the next directory entry. Returns a `Dirent` or `null` when all entries have been read.
784
+
785
+ #### `dir.read(callback)`
786
+
787
+ Callback version of `dir.read()`.
788
+
789
+ #### `const dirent = dir.readSync()`
790
+
791
+ Synchronous version of `dir.read()`.
792
+
793
+ #### `await dir.close()`
794
+
795
+ Close the directory handle.
796
+
797
+ #### `dir.close(callback)`
798
+
799
+ Callback version of `dir.close()`.
800
+
801
+ #### `dir.closeSync()`
802
+
803
+ Synchronous version of `dir.close()`.
804
+
805
+ ### `Dirent`
806
+
807
+ Represents a directory entry, returned when iterating a `Dir` or using `fs.readdir()` with `withFileTypes: true`.
808
+
809
+ #### `dirent.parentPath`
810
+
811
+ The path of the parent directory.
812
+
813
+ #### `dirent.name`
814
+
815
+ The name of the directory entry, as a string or `Buffer` depending on the encoding.
816
+
817
+ #### `dirent.type`
818
+
819
+ The numeric type of the directory entry.
820
+
821
+ #### `dirent.isFile()`
822
+
823
+ Returns `true` if the entry is a regular file.
824
+
825
+ #### `dirent.isDirectory()`
826
+
827
+ Returns `true` if the entry is a directory.
828
+
829
+ #### `dirent.isSymbolicLink()`
830
+
831
+ Returns `true` if the entry is a symbolic link.
832
+
833
+ #### `dirent.isFIFO()`
834
+
835
+ Returns `true` if the entry is a FIFO.
836
+
837
+ #### `dirent.isSocket()`
838
+
839
+ Returns `true` if the entry is a socket.
840
+
841
+ #### `dirent.isCharacterDevice()`
842
+
843
+ Returns `true` if the entry is a character device.
844
+
845
+ #### `dirent.isBlockDevice()`
846
+
847
+ Returns `true` if the entry is a block device.
848
+
849
+ ### `ReadStream`
850
+
851
+ A readable stream for file data, created by `fs.createReadStream()`. Extends `Readable` from <https://github.com/holepunchto/bare-stream>.
852
+
853
+ #### `stream.path`
854
+
855
+ The file path, or `null` if opened by file descriptor.
856
+
857
+ #### `stream.fd`
858
+
859
+ The underlying file descriptor.
860
+
861
+ #### `stream.flags`
862
+
863
+ The flags the file was opened with.
864
+
865
+ #### `stream.mode`
866
+
867
+ The mode the file was opened with.
868
+
869
+ ### `WriteStream`
870
+
871
+ A writable stream for file data, created by `fs.createWriteStream()`. Extends `Writable` from <https://github.com/holepunchto/bare-stream>.
872
+
873
+ #### `stream.path`
874
+
875
+ The file path, or `null` if opened by file descriptor.
876
+
877
+ #### `stream.fd`
878
+
879
+ The underlying file descriptor.
880
+
881
+ #### `stream.flags`
882
+
883
+ The flags the file was opened with.
884
+
885
+ #### `stream.mode`
886
+
887
+ The mode the file was opened with.
888
+
889
+ ### `Watcher`
890
+
891
+ Watches for file system changes, created by `fs.watch()`. Extends `EventEmitter` from <https://github.com/holepunchto/bare-events>.
892
+
893
+ #### `watcher.close()`
894
+
895
+ Stop watching for changes.
896
+
897
+ #### `watcher.ref()`
898
+
899
+ Prevent the event loop from exiting while the watcher is active.
900
+
901
+ #### `watcher.unref()`
902
+
903
+ Allow the event loop to exit even if the watcher is still active.
904
+
905
+ #### `event: 'change'`
906
+
907
+ Emitted with `(eventType, filename)` when a change is detected. `eventType` is either `'rename'` or `'change'`.
908
+
909
+ #### `event: 'error'`
910
+
911
+ Emitted with `(err)` when an error occurs.
912
+
913
+ #### `event: 'close'`
914
+
915
+ Emitted when the watcher is closed.
916
+
917
+ ### `FileHandle`
918
+
919
+ Returned by `require('bare-fs/promises').open()`. Provides an object-oriented API for working with file descriptors.
920
+
921
+ #### `await handle.close()`
922
+
923
+ Close the file handle.
924
+
925
+ #### `const { bytesRead, buffer } = await handle.read(buffer[, offset[, len[, pos]]])`
926
+
927
+ Read from the file into `buffer`.
928
+
929
+ #### `const { bytesRead, buffers } = await handle.readv(buffers[, pos])`
930
+
931
+ Read from the file into an array of `buffers`.
932
+
933
+ #### `const { bytesWritten, buffer } = await handle.write(data[, offset[, len[, pos]]])`
934
+
935
+ Write `data` to the file.
936
+
937
+ #### `const { bytesWritten, buffers } = await handle.writev(buffers[, pos])`
938
+
939
+ Write an array of `buffers` to the file.
940
+
941
+ #### `const stats = await handle.stat()`
942
+
943
+ Get the status of the file.
944
+
945
+ #### `await handle.chmod(mode)`
946
+
947
+ Change the permissions of the file.
948
+
949
+ #### `await handle.chown(uid, gid)`
950
+
951
+ Change the owner and group of the file.
952
+
953
+ **NOTE**: This function is not implemented on Windows.
954
+
955
+ #### `await handle.datasync()`
956
+
957
+ Similar to `fsync`, but does not flush modified metadata unless necessary.
958
+
959
+ #### `await handle.sync()`
960
+
961
+ Flush all modified in-core data of the file.
962
+
963
+ #### `await handle.truncate(len)`
964
+
965
+ Truncate the file.
966
+
967
+ #### `await handle.utimes(mode)`
968
+
969
+ Change the access and modification times of the file.
970
+
971
+ #### `const stream = handle.createReadStream([opts])`
972
+
973
+ Create a readable stream for the file.
974
+
975
+ #### `const stream = handle.createWriteStream([opts])`
976
+
977
+ Create a writable stream for the file.
978
+
979
+ #### `handle.fd`
980
+
981
+ The file descriptor number.
982
+
983
+ #### `event: 'close'`
984
+
985
+ Emitted when the file handle is closed.
986
+
987
+ ## License
988
+
989
+ Apache-2.0
node_modules/bare-fs/binding.c ADDED
@@ -0,0 +1,2889 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <assert.h>
2
+ #include <bare.h>
3
+ #include <js.h>
4
+ #include <stdbool.h>
5
+ #include <stdint.h>
6
+ #include <stdlib.h>
7
+ #include <string.h>
8
+ #include <utf.h>
9
+ #include <uv.h>
10
+
11
+ #ifndef _MSC_VER
12
+ #include <unistd.h>
13
+ #endif
14
+
15
+ typedef struct {
16
+ uv_fs_t handle;
17
+
18
+ js_env_t *env;
19
+ js_ref_t *ctx;
20
+ js_ref_t *on_result;
21
+
22
+ bool exiting;
23
+ bool inflight;
24
+
25
+ js_deferred_teardown_t *teardown;
26
+ } bare_fs_req_t;
27
+
28
+ typedef utf8_t bare_fs_path_t[4096 + 1 /* NULL */];
29
+
30
+ typedef struct {
31
+ uv_dir_t *handle;
32
+ } bare_fs_dir_t;
33
+
34
+ typedef struct {
35
+ uv_fs_event_t handle;
36
+
37
+ js_env_t *env;
38
+ js_ref_t *ctx;
39
+ js_ref_t *on_event;
40
+ js_ref_t *on_close;
41
+
42
+ bool exiting;
43
+ bool closing;
44
+
45
+ js_deferred_teardown_t *teardown;
46
+ } bare_fs_watcher_t;
47
+
48
+ typedef uv_dirent_t bare_fs_dirent_t;
49
+
50
+ enum {
51
+ bare_fs_async = true,
52
+ bare_fs_sync = false
53
+ };
54
+
55
+ static inline void
56
+ bare_fs__request_destroy(bare_fs_req_t *req) {
57
+ int err;
58
+
59
+ js_env_t *env = req->env;
60
+
61
+ js_deferred_teardown_t *teardown = req->teardown;
62
+
63
+ uv_fs_req_cleanup(&req->handle);
64
+
65
+ err = js_delete_reference(env, req->on_result);
66
+ assert(err == 0);
67
+
68
+ err = js_delete_reference(env, req->ctx);
69
+ assert(err == 0);
70
+
71
+ err = js_finish_deferred_teardown_callback(teardown);
72
+ assert(err == 0);
73
+ }
74
+
75
+ static void
76
+ bare_fs__on_request_teardown(js_deferred_teardown_t *handle, void *data) {
77
+ int err;
78
+
79
+ bare_fs_req_t *req = (bare_fs_req_t *) data;
80
+
81
+ req->exiting = true;
82
+
83
+ if (req->inflight) {
84
+ err = uv_cancel((uv_req_t *) &req->handle);
85
+ if (err < 0) return;
86
+ }
87
+
88
+ bare_fs__request_destroy(req);
89
+ }
90
+
91
+ static inline void
92
+ bare_fs__on_request_result(uv_fs_t *handle) {
93
+ int err;
94
+
95
+ bare_fs_req_t *req = (bare_fs_req_t *) handle;
96
+
97
+ req->inflight = false;
98
+
99
+ if (req->exiting) return bare_fs__request_destroy(req);
100
+
101
+ js_env_t *env = req->env;
102
+
103
+ js_handle_scope_t *scope;
104
+ err = js_open_handle_scope(env, &scope);
105
+ assert(err == 0);
106
+
107
+ js_value_t *ctx;
108
+ err = js_get_reference_value(env, req->ctx, &ctx);
109
+ assert(err == 0);
110
+
111
+ js_value_t *on_result;
112
+ err = js_get_reference_value(env, req->on_result, &on_result);
113
+ assert(err == 0);
114
+
115
+ int status = handle->result;
116
+
117
+ js_value_t *args[2];
118
+
119
+ if (status < 0) {
120
+ js_value_t *code;
121
+ err = js_create_string_utf8(env, (utf8_t *) uv_err_name(status), -1, &code);
122
+ assert(err == 0);
123
+
124
+ js_value_t *message;
125
+ err = js_create_string_utf8(env, (utf8_t *) uv_strerror(status), -1, &message);
126
+ assert(err == 0);
127
+
128
+ err = js_create_error(env, code, message, &args[0]);
129
+ assert(err == 0);
130
+ } else {
131
+ err = js_get_null(env, &args[0]);
132
+ assert(err == 0);
133
+ }
134
+
135
+ err = js_create_int32(env, status, &args[1]);
136
+ assert(err == 0);
137
+
138
+ err = js_call_function(env, ctx, on_result, 2, args, NULL);
139
+ (void) err;
140
+
141
+ err = js_close_handle_scope(env, scope);
142
+ assert(err == 0);
143
+ }
144
+
145
+ static inline int
146
+ bare_fs__request_pending(js_env_t *env, bare_fs_req_t *req, bool async, int *result) {
147
+ int err;
148
+
149
+ if (async) {
150
+ req->inflight = true;
151
+
152
+ return 0;
153
+ }
154
+
155
+ int status = req->handle.result;
156
+
157
+ if (status < 0) {
158
+ err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
159
+ assert(err == 0);
160
+
161
+ return -1;
162
+ }
163
+
164
+ if (result) *result = status;
165
+
166
+ return 1;
167
+ }
168
+
169
+ static js_value_t *
170
+ bare_fs_request_init(js_env_t *env, js_callback_info_t *info) {
171
+ int err;
172
+
173
+ size_t argc = 2;
174
+ js_value_t *argv[2];
175
+
176
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
177
+ assert(err == 0);
178
+
179
+ assert(argc == 2);
180
+
181
+ js_value_t *handle;
182
+
183
+ bare_fs_req_t *req;
184
+ err = js_create_arraybuffer(env, sizeof(bare_fs_req_t), (void **) &req, &handle);
185
+ assert(err == 0);
186
+
187
+ req->env = env;
188
+ req->exiting = false;
189
+ req->inflight = false;
190
+
191
+ err = js_create_reference(env, argv[0], 1, &req->ctx);
192
+ assert(err == 0);
193
+
194
+ err = js_create_reference(env, argv[1], 1, &req->on_result);
195
+ assert(err == 0);
196
+
197
+ err = js_add_deferred_teardown_callback(env, bare_fs__on_request_teardown, (void *) req, &req->teardown);
198
+ assert(err == 0);
199
+
200
+ return handle;
201
+ }
202
+
203
+ static js_value_t *
204
+ bare_fs_request_destroy(js_env_t *env, js_callback_info_t *info) {
205
+ int err;
206
+
207
+ size_t argc = 1;
208
+ js_value_t *argv[1];
209
+
210
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
211
+ assert(err == 0);
212
+
213
+ assert(argc == 1);
214
+
215
+ bare_fs_req_t *req;
216
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
217
+ assert(err == 0);
218
+
219
+ bare_fs__request_destroy(req);
220
+
221
+ return NULL;
222
+ }
223
+
224
+ static js_value_t *
225
+ bare_fs_request_reset(js_env_t *env, js_callback_info_t *info) {
226
+ int err;
227
+
228
+ size_t argc = 1;
229
+ js_value_t *argv[1];
230
+
231
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
232
+ assert(err == 0);
233
+
234
+ assert(argc == 1);
235
+
236
+ bare_fs_req_t *req;
237
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
238
+ assert(err == 0);
239
+
240
+ uv_fs_req_cleanup(&req->handle);
241
+
242
+ return NULL;
243
+ }
244
+
245
+ static js_value_t *
246
+ bare_fs_request_result_stat(js_env_t *env, js_callback_info_t *info) {
247
+ int err;
248
+
249
+ size_t argc = 1;
250
+ js_value_t *argv[1];
251
+
252
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
253
+ assert(err == 0);
254
+
255
+ assert(argc == 1);
256
+
257
+ bare_fs_req_t *req;
258
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
259
+ assert(err == 0);
260
+
261
+ js_value_t *result;
262
+ err = js_create_array_with_length(env, 14, &result);
263
+ assert(err == 0);
264
+
265
+ uint32_t i = 0;
266
+
267
+ #define V(property) \
268
+ { \
269
+ js_value_t *value; \
270
+ err = js_create_int64(env, req->handle.statbuf.st_##property, &value); \
271
+ assert(err == 0); \
272
+ \
273
+ err = js_set_element(env, result, i++, value); \
274
+ assert(err == 0); \
275
+ }
276
+ V(dev)
277
+ V(mode)
278
+ V(nlink)
279
+ V(uid)
280
+ V(gid)
281
+ V(rdev)
282
+ V(blksize)
283
+ V(ino)
284
+ V(size)
285
+ V(blocks)
286
+ #undef V
287
+
288
+ #define V(property) \
289
+ { \
290
+ uv_timespec_t time = req->handle.statbuf.st_##property; \
291
+ \
292
+ js_value_t *value; \
293
+ err = js_create_int64(env, time.tv_sec * 1000 + time.tv_nsec / 1000000, &value); \
294
+ assert(err == 0); \
295
+ \
296
+ err = js_set_element(env, result, i++, value); \
297
+ assert(err == 0); \
298
+ }
299
+ V(atim)
300
+ V(mtim)
301
+ V(ctim)
302
+ V(birthtim)
303
+ #undef V
304
+
305
+ return result;
306
+ }
307
+
308
+ static js_value_t *
309
+ bare_fs_request_result_statfs(js_env_t *env, js_callback_info_t *info) {
310
+ int err;
311
+
312
+ size_t argc = 1;
313
+ js_value_t *argv[1];
314
+
315
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
316
+ assert(err == 0);
317
+
318
+ assert(argc == 1);
319
+
320
+ bare_fs_req_t *req;
321
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
322
+ assert(err == 0);
323
+
324
+ uv_statfs_t *statfs = req->handle.ptr;
325
+
326
+ js_value_t *result;
327
+ err = js_create_array_with_length(env, 7, &result);
328
+ assert(err == 0);
329
+
330
+ uint32_t i = 0;
331
+
332
+ #define V(property) \
333
+ { \
334
+ js_value_t *value; \
335
+ err = js_create_int64(env, statfs->f_##property, &value); \
336
+ assert(err == 0); \
337
+ \
338
+ err = js_set_element(env, result, i++, value); \
339
+ assert(err == 0); \
340
+ }
341
+ V(type)
342
+ V(bsize)
343
+ V(blocks)
344
+ V(bfree)
345
+ V(bavail)
346
+ V(files)
347
+ V(ffree)
348
+ #undef V
349
+
350
+ return result;
351
+ }
352
+
353
+ static js_value_t *
354
+ bare_fs_request_result_string(js_env_t *env, js_callback_info_t *info) {
355
+ int err;
356
+
357
+ size_t argc = 1;
358
+ js_value_t *argv[1];
359
+
360
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
361
+ assert(err == 0);
362
+
363
+ assert(argc == 1);
364
+
365
+ bare_fs_req_t *req;
366
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
367
+ assert(err == 0);
368
+
369
+ size_t len = strlen(req->handle.ptr);
370
+
371
+ js_value_t *result;
372
+
373
+ void *data;
374
+ err = js_create_arraybuffer(env, len, (void *) &data, &result);
375
+ assert(err == 0);
376
+
377
+ strncpy(data, req->handle.ptr, len);
378
+
379
+ return result;
380
+ }
381
+
382
+ static js_value_t *
383
+ bare_fs_request_result_path(js_env_t *env, js_callback_info_t *info) {
384
+ int err;
385
+
386
+ size_t argc = 1;
387
+ js_value_t *argv[1];
388
+
389
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
390
+ assert(err == 0);
391
+
392
+ assert(argc == 1);
393
+
394
+ bare_fs_req_t *req;
395
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
396
+ assert(err == 0);
397
+
398
+ const char *path = req->handle.path;
399
+
400
+ js_value_t *result;
401
+ err = js_create_string_utf8(env, (utf8_t *) path, strlen(path), &result);
402
+ assert(err == 0);
403
+
404
+ return result;
405
+ }
406
+
407
+ static js_value_t *
408
+ bare_fs_request_result_dir(js_env_t *env, js_callback_info_t *info) {
409
+ int err;
410
+
411
+ size_t argc = 1;
412
+ js_value_t *argv[1];
413
+
414
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
415
+ assert(err == 0);
416
+
417
+ assert(argc == 1);
418
+
419
+ bare_fs_req_t *req;
420
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
421
+ assert(err == 0);
422
+
423
+ js_value_t *result;
424
+
425
+ bare_fs_dir_t *dir;
426
+ err = js_create_arraybuffer(env, sizeof(bare_fs_dir_t), (void **) &dir, &result);
427
+ assert(err == 0);
428
+
429
+ dir->handle = req->handle.ptr;
430
+
431
+ return result;
432
+ }
433
+
434
+ static js_value_t *
435
+ bare_fs_request_result_dirents(js_env_t *env, js_callback_info_t *info) {
436
+ int err;
437
+
438
+ size_t argc = 1;
439
+ js_value_t *argv[1];
440
+
441
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
442
+ assert(err == 0);
443
+
444
+ assert(argc == 1);
445
+
446
+ bare_fs_req_t *req;
447
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
448
+ assert(err == 0);
449
+
450
+ size_t len = req->handle.result;
451
+
452
+ js_value_t *result;
453
+ err = js_create_array_with_length(env, len, &result);
454
+ assert(err == 0);
455
+
456
+ uv_dir_t *dir = req->handle.ptr;
457
+
458
+ for (uint32_t i = 0; i < len; i++) {
459
+ uv_dirent_t *dirent = &dir->dirents[i];
460
+
461
+ js_value_t *entry;
462
+ err = js_create_object(env, &entry);
463
+ assert(err == 0);
464
+
465
+ err = js_set_element(env, result, i, entry);
466
+ assert(err == 0);
467
+
468
+ size_t name_len = strlen(dirent->name);
469
+
470
+ js_value_t *name;
471
+
472
+ void *data;
473
+ err = js_create_arraybuffer(env, name_len, &data, &name);
474
+ assert(err == 0);
475
+
476
+ memcpy(data, dirent->name, name_len);
477
+
478
+ err = js_set_named_property(env, entry, "name", name);
479
+ assert(err == 0);
480
+
481
+ js_value_t *type;
482
+ err = js_create_uint32(env, dirent->type, &type);
483
+ assert(err == 0);
484
+
485
+ err = js_set_named_property(env, entry, "type", type);
486
+ assert(err == 0);
487
+ }
488
+
489
+ return result;
490
+ }
491
+
492
+ static void
493
+ bare_fs__on_open(uv_fs_t *handle) {
494
+ int err;
495
+
496
+ bare_fs_req_t *req = (bare_fs_req_t *) handle;
497
+
498
+ int status = handle->result;
499
+
500
+ if (req->exiting && status >= 0) {
501
+ int fd = status;
502
+
503
+ uv_fs_req_cleanup(handle);
504
+
505
+ err = uv_fs_close(handle->loop, handle, fd, NULL);
506
+ assert(err == 0);
507
+ }
508
+
509
+ bare_fs__on_request_result(handle);
510
+ }
511
+
512
+ static inline js_value_t *
513
+ bare_fs__open(js_env_t *env, js_callback_info_t *info, bool async) {
514
+ int err;
515
+
516
+ size_t argc = 4;
517
+ js_value_t *argv[4];
518
+
519
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
520
+ assert(err == 0);
521
+
522
+ assert(argc == 4);
523
+
524
+ bare_fs_req_t *req;
525
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
526
+ assert(err == 0);
527
+
528
+ bare_fs_path_t path;
529
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
530
+ assert(err == 0);
531
+
532
+ int32_t flags;
533
+ err = js_get_value_int32(env, argv[2], &flags);
534
+ assert(err == 0);
535
+
536
+ int32_t mode;
537
+ err = js_get_value_int32(env, argv[3], &mode);
538
+ assert(err == 0);
539
+
540
+ uv_loop_t *loop;
541
+ err = js_get_env_loop(env, &loop);
542
+ assert(err == 0);
543
+
544
+ err = uv_fs_open(loop, &req->handle, (char *) path, flags, mode, async ? bare_fs__on_open : NULL);
545
+ (void) err;
546
+
547
+ int status;
548
+ err = bare_fs__request_pending(env, req, async, &status);
549
+ if (err != 1) return NULL;
550
+
551
+ js_value_t *result;
552
+ err = js_create_int32(env, status, &result);
553
+ assert(err == 0);
554
+
555
+ return result;
556
+ }
557
+
558
+ static js_value_t *
559
+ bare_fs_open(js_env_t *env, js_callback_info_t *info) {
560
+ return bare_fs__open(env, info, bare_fs_async);
561
+ }
562
+
563
+ static js_value_t *
564
+ bare_fs_open_sync(js_env_t *env, js_callback_info_t *info) {
565
+ return bare_fs__open(env, info, bare_fs_sync);
566
+ }
567
+
568
+ static void
569
+ bare_fs__on_close(uv_fs_t *handle) {
570
+ bare_fs__on_request_result(handle);
571
+ }
572
+
573
+ static inline js_value_t *
574
+ bare_fs__close(js_env_t *env, js_callback_info_t *info, bool async) {
575
+ int err;
576
+
577
+ size_t argc = 2;
578
+ js_value_t *argv[2];
579
+
580
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
581
+ assert(err == 0);
582
+
583
+ assert(argc == 2);
584
+
585
+ bare_fs_req_t *req;
586
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
587
+ assert(err == 0);
588
+
589
+ uint32_t fd;
590
+ err = js_get_value_uint32(env, argv[1], &fd);
591
+ assert(err == 0);
592
+
593
+ uv_loop_t *loop;
594
+ err = js_get_env_loop(env, &loop);
595
+ assert(err == 0);
596
+
597
+ err = uv_fs_close(loop, &req->handle, fd, async ? bare_fs__on_close : NULL);
598
+ (void) err;
599
+
600
+ err = bare_fs__request_pending(env, req, async, NULL);
601
+ (void) err;
602
+
603
+ return NULL;
604
+ }
605
+
606
+ static js_value_t *
607
+ bare_fs_close(js_env_t *env, js_callback_info_t *info) {
608
+ return bare_fs__close(env, info, bare_fs_async);
609
+ }
610
+
611
+ static js_value_t *
612
+ bare_fs_close_sync(js_env_t *env, js_callback_info_t *info) {
613
+ return bare_fs__close(env, info, bare_fs_sync);
614
+ }
615
+
616
+ static void
617
+ bare_fs__on_access(uv_fs_t *handle) {
618
+ bare_fs__on_request_result(handle);
619
+ }
620
+
621
+ static inline js_value_t *
622
+ bare_fs__access(js_env_t *env, js_callback_info_t *info, bool async) {
623
+ int err;
624
+
625
+ size_t argc = 3;
626
+ js_value_t *argv[3];
627
+
628
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
629
+ assert(err == 0);
630
+
631
+ assert(argc == 3);
632
+
633
+ bare_fs_req_t *req;
634
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
635
+ assert(err == 0);
636
+
637
+ bare_fs_path_t path;
638
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
639
+ assert(err == 0);
640
+
641
+ int32_t mode;
642
+ err = js_get_value_int32(env, argv[2], &mode);
643
+ assert(err == 0);
644
+
645
+ uv_loop_t *loop;
646
+ err = js_get_env_loop(env, &loop);
647
+ assert(err == 0);
648
+
649
+ err = uv_fs_access(loop, &req->handle, (char *) path, mode, async ? bare_fs__on_access : NULL);
650
+ (void) err;
651
+
652
+ err = bare_fs__request_pending(env, req, async, NULL);
653
+ (void) err;
654
+
655
+ return NULL;
656
+ }
657
+
658
+ static js_value_t *
659
+ bare_fs_access(js_env_t *env, js_callback_info_t *info) {
660
+ return bare_fs__access(env, info, bare_fs_async);
661
+ }
662
+
663
+ static js_value_t *
664
+ bare_fs_access_sync(js_env_t *env, js_callback_info_t *info) {
665
+ return bare_fs__access(env, info, bare_fs_sync);
666
+ }
667
+
668
+ static void
669
+ bare_fs__on_read(uv_fs_t *handle) {
670
+ bare_fs__on_request_result(handle);
671
+ }
672
+
673
+ static inline js_value_t *
674
+ bare_fs__read(js_env_t *env, js_callback_info_t *info, bool async) {
675
+ int err;
676
+
677
+ size_t argc = 6;
678
+ js_value_t *argv[6];
679
+
680
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
681
+ assert(err == 0);
682
+
683
+ assert(argc == 6);
684
+
685
+ bare_fs_req_t *req;
686
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
687
+ assert(err == 0);
688
+
689
+ uint32_t fd;
690
+ err = js_get_value_uint32(env, argv[1], &fd);
691
+ assert(err == 0);
692
+
693
+ uint8_t *data;
694
+ size_t data_len;
695
+ err = js_get_typedarray_info(env, argv[2], NULL, (void **) &data, &data_len, NULL, NULL);
696
+ assert(err == 0);
697
+
698
+ uint32_t offset;
699
+ err = js_get_value_uint32(env, argv[3], &offset);
700
+ assert(err == 0);
701
+
702
+ uint32_t len;
703
+ err = js_get_value_uint32(env, argv[4], &len);
704
+ assert(err == 0);
705
+
706
+ if (offset >= data_len) len = 0;
707
+ else if (offset + len >= data_len) len = data_len - offset;
708
+
709
+ int64_t pos;
710
+ err = js_get_value_int64(env, argv[5], &pos);
711
+ assert(err == 0);
712
+
713
+ uv_loop_t *loop;
714
+ err = js_get_env_loop(env, &loop);
715
+ assert(err == 0);
716
+
717
+ uv_buf_t buf = uv_buf_init((void *) (data + offset), len);
718
+
719
+ err = uv_fs_read(loop, &req->handle, fd, &buf, 1, pos, async ? bare_fs__on_read : NULL);
720
+ (void) err;
721
+
722
+ int status;
723
+ err = bare_fs__request_pending(env, req, async, &status);
724
+ if (err != 1) return NULL;
725
+
726
+ js_value_t *result;
727
+ err = js_create_int32(env, status, &result);
728
+ assert(err == 0);
729
+
730
+ return result;
731
+ }
732
+
733
+ static js_value_t *
734
+ bare_fs_read(js_env_t *env, js_callback_info_t *info) {
735
+ return bare_fs__read(env, info, bare_fs_async);
736
+ }
737
+
738
+ static js_value_t *
739
+ bare_fs_read_sync(js_env_t *env, js_callback_info_t *info) {
740
+ return bare_fs__read(env, info, bare_fs_sync);
741
+ }
742
+
743
+ static void
744
+ bare_fs__on_readv(uv_fs_t *handle) {
745
+ bare_fs__on_request_result(handle);
746
+ }
747
+
748
+ static inline js_value_t *
749
+ bare_fs__readv(js_env_t *env, js_callback_info_t *info, bool async) {
750
+ int err;
751
+
752
+ size_t argc = 4;
753
+ js_value_t *argv[4];
754
+
755
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
756
+ assert(err == 0);
757
+
758
+ assert(argc == 4);
759
+
760
+ bare_fs_req_t *req;
761
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
762
+ assert(err == 0);
763
+
764
+ uint32_t fd;
765
+ err = js_get_value_uint32(env, argv[1], &fd);
766
+ assert(err == 0);
767
+
768
+ int64_t pos;
769
+ err = js_get_value_int64(env, argv[3], &pos);
770
+ assert(err == 0);
771
+
772
+ uv_loop_t *loop;
773
+ err = js_get_env_loop(env, &loop);
774
+ assert(err == 0);
775
+
776
+ js_value_t *arr = argv[2];
777
+
778
+ uint32_t bufs_len;
779
+ err = js_get_array_length(env, arr, &bufs_len);
780
+ assert(err == 0);
781
+
782
+ uv_buf_t *bufs = malloc(sizeof(uv_buf_t) * bufs_len);
783
+
784
+ js_value_t **elements = malloc(bufs_len * sizeof(js_value_t *));
785
+ err = js_get_array_elements(env, arr, elements, bufs_len, 0, NULL);
786
+ assert(err == 0);
787
+
788
+ for (uint32_t i = 0; i < bufs_len; i++) {
789
+ js_value_t *item = elements[i];
790
+
791
+ uv_buf_t *buf = &bufs[i];
792
+ err = js_get_typedarray_info(env, item, NULL, (void **) &buf->base, (size_t *) &buf->len, NULL, NULL);
793
+ assert(err == 0);
794
+ }
795
+
796
+ err = uv_fs_read(loop, &req->handle, fd, bufs, bufs_len, pos, async ? bare_fs__on_readv : NULL);
797
+ (void) err;
798
+
799
+ free(elements);
800
+ free(bufs);
801
+
802
+ int status;
803
+ err = bare_fs__request_pending(env, req, async, &status);
804
+ if (err != 1) return NULL;
805
+
806
+ js_value_t *result;
807
+ err = js_create_int32(env, status, &result);
808
+ assert(err == 0);
809
+
810
+ return result;
811
+ }
812
+
813
+ static js_value_t *
814
+ bare_fs_readv(js_env_t *env, js_callback_info_t *info) {
815
+ return bare_fs__readv(env, info, bare_fs_async);
816
+ }
817
+
818
+ static js_value_t *
819
+ bare_fs_readv_sync(js_env_t *env, js_callback_info_t *info) {
820
+ return bare_fs__readv(env, info, bare_fs_sync);
821
+ }
822
+
823
+ static void
824
+ bare_fs__on_write(uv_fs_t *handle) {
825
+ bare_fs__on_request_result(handle);
826
+ }
827
+
828
+ static inline js_value_t *
829
+ bare_fs__write(js_env_t *env, js_callback_info_t *info, bool async) {
830
+ int err;
831
+
832
+ size_t argc = 6;
833
+ js_value_t *argv[6];
834
+
835
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
836
+ assert(err == 0);
837
+
838
+ assert(argc == 6);
839
+
840
+ bare_fs_req_t *req;
841
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
842
+ assert(err == 0);
843
+
844
+ uint32_t fd;
845
+ err = js_get_value_uint32(env, argv[1], &fd);
846
+ assert(err == 0);
847
+
848
+ uint8_t *data;
849
+ size_t data_len;
850
+ err = js_get_typedarray_info(env, argv[2], NULL, (void **) &data, &data_len, NULL, NULL);
851
+ assert(err == 0);
852
+
853
+ uint32_t offset;
854
+ err = js_get_value_uint32(env, argv[3], &offset);
855
+ assert(err == 0);
856
+
857
+ uint32_t len;
858
+ err = js_get_value_uint32(env, argv[4], &len);
859
+ assert(err == 0);
860
+
861
+ if (offset >= data_len) len = 0;
862
+ else if (offset + len >= data_len) len = data_len - offset;
863
+
864
+ int64_t pos;
865
+ err = js_get_value_int64(env, argv[5], &pos);
866
+ assert(err == 0);
867
+
868
+ uv_loop_t *loop;
869
+ err = js_get_env_loop(env, &loop);
870
+ assert(err == 0);
871
+
872
+ uv_buf_t buf = uv_buf_init((void *) (data + offset), len);
873
+
874
+ err = uv_fs_write(loop, &req->handle, fd, &buf, 1, pos, async ? bare_fs__on_write : NULL);
875
+ (void) err;
876
+
877
+ int status;
878
+ err = bare_fs__request_pending(env, req, async, &status);
879
+ if (err != 1) return NULL;
880
+
881
+ js_value_t *result;
882
+ err = js_create_int32(env, status, &result);
883
+ assert(err == 0);
884
+
885
+ return result;
886
+ }
887
+
888
+ static js_value_t *
889
+ bare_fs_write(js_env_t *env, js_callback_info_t *info) {
890
+ return bare_fs__write(env, info, bare_fs_async);
891
+ }
892
+
893
+ static js_value_t *
894
+ bare_fs_write_sync(js_env_t *env, js_callback_info_t *info) {
895
+ return bare_fs__write(env, info, bare_fs_sync);
896
+ }
897
+
898
+ static void
899
+ bare_fs__on_writev(uv_fs_t *handle) {
900
+ bare_fs__on_request_result(handle);
901
+ }
902
+
903
+ static inline js_value_t *
904
+ bare_fs__writev(js_env_t *env, js_callback_info_t *info, bool async) {
905
+ int err;
906
+
907
+ size_t argc = 4;
908
+ js_value_t *argv[4];
909
+
910
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
911
+ assert(err == 0);
912
+
913
+ assert(argc == 4);
914
+
915
+ bare_fs_req_t *req;
916
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
917
+ assert(err == 0);
918
+
919
+ uint32_t fd;
920
+ err = js_get_value_uint32(env, argv[1], &fd);
921
+ assert(err == 0);
922
+
923
+ int64_t pos;
924
+ err = js_get_value_int64(env, argv[3], &pos);
925
+ assert(err == 0);
926
+
927
+ uv_loop_t *loop;
928
+ err = js_get_env_loop(env, &loop);
929
+ assert(err == 0);
930
+
931
+ js_value_t *arr = argv[2];
932
+
933
+ uint32_t bufs_len;
934
+ err = js_get_array_length(env, arr, &bufs_len);
935
+ assert(err == 0);
936
+
937
+ uv_buf_t *bufs = malloc(sizeof(uv_buf_t) * bufs_len);
938
+
939
+ js_value_t **elements = malloc(bufs_len * sizeof(js_value_t *));
940
+
941
+ err = js_get_array_elements(env, arr, elements, bufs_len, 0, NULL);
942
+ assert(err == 0);
943
+
944
+ for (uint32_t i = 0; i < bufs_len; i++) {
945
+ js_value_t *item = elements[i];
946
+
947
+ uv_buf_t *buf = &bufs[i];
948
+ err = js_get_typedarray_info(env, item, NULL, (void **) &buf->base, (size_t *) &buf->len, NULL, NULL);
949
+ assert(err == 0);
950
+ }
951
+
952
+ err = uv_fs_write(loop, &req->handle, fd, bufs, bufs_len, pos, async ? bare_fs__on_writev : NULL);
953
+ (void) err;
954
+
955
+ free(elements);
956
+ free(bufs);
957
+
958
+ int status;
959
+ err = bare_fs__request_pending(env, req, async, &status);
960
+ if (err != 1) return NULL;
961
+
962
+ js_value_t *result;
963
+ err = js_create_int32(env, status, &result);
964
+ assert(err == 0);
965
+
966
+ return result;
967
+ }
968
+
969
+ static js_value_t *
970
+ bare_fs_writev(js_env_t *env, js_callback_info_t *info) {
971
+ return bare_fs__writev(env, info, bare_fs_async);
972
+ }
973
+
974
+ static js_value_t *
975
+ bare_fs_writev_sync(js_env_t *env, js_callback_info_t *info) {
976
+ return bare_fs__writev(env, info, bare_fs_sync);
977
+ }
978
+
979
+ static void
980
+ bare_fs__on_ftruncate(uv_fs_t *handle) {
981
+ bare_fs__on_request_result(handle);
982
+ }
983
+
984
+ static inline js_value_t *
985
+ bare_fs__ftruncate(js_env_t *env, js_callback_info_t *info, bool async) {
986
+ int err;
987
+
988
+ size_t argc = 3;
989
+ js_value_t *argv[3];
990
+
991
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
992
+ assert(err == 0);
993
+
994
+ assert(argc == 3);
995
+
996
+ bare_fs_req_t *req;
997
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
998
+ assert(err == 0);
999
+
1000
+ uint32_t fd;
1001
+ err = js_get_value_uint32(env, argv[1], &fd);
1002
+ assert(err == 0);
1003
+
1004
+ int64_t len;
1005
+ err = js_get_value_int64(env, argv[2], &len);
1006
+ assert(err == 0);
1007
+
1008
+ uv_loop_t *loop;
1009
+ err = js_get_env_loop(env, &loop);
1010
+ assert(err == 0);
1011
+
1012
+ err = uv_fs_ftruncate(loop, &req->handle, fd, len, async ? bare_fs__on_ftruncate : NULL);
1013
+ (void) err;
1014
+
1015
+ err = bare_fs__request_pending(env, req, async, NULL);
1016
+ (void) err;
1017
+
1018
+ return NULL;
1019
+ }
1020
+
1021
+ static js_value_t *
1022
+ bare_fs_ftruncate(js_env_t *env, js_callback_info_t *info) {
1023
+ return bare_fs__ftruncate(env, info, bare_fs_async);
1024
+ }
1025
+
1026
+ static js_value_t *
1027
+ bare_fs_ftruncate_sync(js_env_t *env, js_callback_info_t *info) {
1028
+ return bare_fs__ftruncate(env, info, bare_fs_sync);
1029
+ }
1030
+
1031
+ static void
1032
+ bare_fs__on_chmod(uv_fs_t *handle) {
1033
+ bare_fs__on_request_result(handle);
1034
+ }
1035
+
1036
+ static inline js_value_t *
1037
+ bare_fs__chmod(js_env_t *env, js_callback_info_t *info, bool async) {
1038
+ int err;
1039
+
1040
+ size_t argc = 3;
1041
+ js_value_t *argv[3];
1042
+
1043
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1044
+ assert(err == 0);
1045
+
1046
+ assert(argc == 3);
1047
+
1048
+ bare_fs_req_t *req;
1049
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1050
+ assert(err == 0);
1051
+
1052
+ bare_fs_path_t path;
1053
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1054
+ assert(err == 0);
1055
+
1056
+ int32_t mode;
1057
+ err = js_get_value_int32(env, argv[2], &mode);
1058
+ assert(err == 0);
1059
+
1060
+ uv_loop_t *loop;
1061
+ err = js_get_env_loop(env, &loop);
1062
+ assert(err == 0);
1063
+
1064
+ err = uv_fs_chmod(loop, &req->handle, (char *) path, mode, async ? bare_fs__on_chmod : NULL);
1065
+ (void) err;
1066
+
1067
+ err = bare_fs__request_pending(env, req, async, NULL);
1068
+ (void) err;
1069
+
1070
+ return NULL;
1071
+ }
1072
+
1073
+ static js_value_t *
1074
+ bare_fs_chmod(js_env_t *env, js_callback_info_t *info) {
1075
+ return bare_fs__chmod(env, info, bare_fs_async);
1076
+ }
1077
+
1078
+ static js_value_t *
1079
+ bare_fs_chmod_sync(js_env_t *env, js_callback_info_t *info) {
1080
+ return bare_fs__chmod(env, info, bare_fs_sync);
1081
+ }
1082
+
1083
+ static void
1084
+ bare_fs__on_fchmod(uv_fs_t *handle) {
1085
+ bare_fs__on_request_result(handle);
1086
+ }
1087
+
1088
+ static inline js_value_t *
1089
+ bare_fs__fchmod(js_env_t *env, js_callback_info_t *info, bool async) {
1090
+ int err;
1091
+
1092
+ size_t argc = 3;
1093
+ js_value_t *argv[3];
1094
+
1095
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1096
+ assert(err == 0);
1097
+
1098
+ assert(argc == 3);
1099
+
1100
+ bare_fs_req_t *req;
1101
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1102
+ assert(err == 0);
1103
+
1104
+ uint32_t fd;
1105
+ err = js_get_value_uint32(env, argv[1], &fd);
1106
+ assert(err == 0);
1107
+
1108
+ int32_t mode;
1109
+ err = js_get_value_int32(env, argv[2], &mode);
1110
+ assert(err == 0);
1111
+
1112
+ uv_loop_t *loop;
1113
+ err = js_get_env_loop(env, &loop);
1114
+ assert(err == 0);
1115
+
1116
+ err = uv_fs_fchmod(loop, &req->handle, fd, mode, async ? bare_fs__on_fchmod : NULL);
1117
+ (void) err;
1118
+
1119
+ err = bare_fs__request_pending(env, req, async, NULL);
1120
+ (void) err;
1121
+
1122
+ return NULL;
1123
+ }
1124
+
1125
+ static js_value_t *
1126
+ bare_fs_fchmod(js_env_t *env, js_callback_info_t *info) {
1127
+ return bare_fs__fchmod(env, info, bare_fs_async);
1128
+ }
1129
+
1130
+ static js_value_t *
1131
+ bare_fs_fchmod_sync(js_env_t *env, js_callback_info_t *info) {
1132
+ return bare_fs__fchmod(env, info, bare_fs_sync);
1133
+ }
1134
+
1135
+ static void
1136
+ bare_fs__on_chown(uv_fs_t *handle) {
1137
+ bare_fs__on_request_result(handle);
1138
+ }
1139
+
1140
+ static inline js_value_t *
1141
+ bare_fs__chown(js_env_t *env, js_callback_info_t *info, bool async) {
1142
+ int err;
1143
+
1144
+ size_t argc = 4;
1145
+ js_value_t *argv[4];
1146
+
1147
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1148
+ assert(err == 0);
1149
+
1150
+ assert(argc == 4);
1151
+
1152
+ bare_fs_req_t *req;
1153
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1154
+ assert(err == 0);
1155
+
1156
+ bare_fs_path_t path;
1157
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1158
+ assert(err == 0);
1159
+
1160
+ uint32_t uid;
1161
+ err = js_get_value_uint32(env, argv[2], &uid);
1162
+ assert(err == 0);
1163
+
1164
+ uint32_t gid;
1165
+ err = js_get_value_uint32(env, argv[3], &gid);
1166
+ assert(err == 0);
1167
+
1168
+ uv_loop_t *loop;
1169
+ err = js_get_env_loop(env, &loop);
1170
+ assert(err == 0);
1171
+
1172
+ err = uv_fs_chown(loop, &req->handle, (char *) path, uid, gid, async ? bare_fs__on_chown : NULL);
1173
+ (void) err;
1174
+
1175
+ err = bare_fs__request_pending(env, req, async, NULL);
1176
+ (void) err;
1177
+
1178
+ return NULL;
1179
+ }
1180
+
1181
+ static js_value_t *
1182
+ bare_fs_chown(js_env_t *env, js_callback_info_t *info) {
1183
+ return bare_fs__chown(env, info, bare_fs_async);
1184
+ }
1185
+
1186
+ static js_value_t *
1187
+ bare_fs_chown_sync(js_env_t *env, js_callback_info_t *info) {
1188
+ return bare_fs__chown(env, info, bare_fs_sync);
1189
+ }
1190
+
1191
+ static void
1192
+ bare_fs__on_lchown(uv_fs_t *handle) {
1193
+ bare_fs__on_request_result(handle);
1194
+ }
1195
+
1196
+ static inline js_value_t *
1197
+ bare_fs__lchown(js_env_t *env, js_callback_info_t *info, bool async) {
1198
+ int err;
1199
+
1200
+ size_t argc = 4;
1201
+ js_value_t *argv[4];
1202
+
1203
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1204
+ assert(err == 0);
1205
+
1206
+ assert(argc == 4);
1207
+
1208
+ bare_fs_req_t *req;
1209
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1210
+ assert(err == 0);
1211
+
1212
+ bare_fs_path_t path;
1213
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1214
+ assert(err == 0);
1215
+
1216
+ uint32_t uid;
1217
+ err = js_get_value_uint32(env, argv[2], &uid);
1218
+ assert(err == 0);
1219
+
1220
+ uint32_t gid;
1221
+ err = js_get_value_uint32(env, argv[3], &gid);
1222
+ assert(err == 0);
1223
+
1224
+ uv_loop_t *loop;
1225
+ err = js_get_env_loop(env, &loop);
1226
+ assert(err == 0);
1227
+
1228
+ err = uv_fs_lchown(loop, &req->handle, (char *) path, uid, gid, async ? bare_fs__on_lchown : NULL);
1229
+ (void) err;
1230
+
1231
+ err = bare_fs__request_pending(env, req, async, NULL);
1232
+ (void) err;
1233
+
1234
+ return NULL;
1235
+ }
1236
+
1237
+ static js_value_t *
1238
+ bare_fs_lchown(js_env_t *env, js_callback_info_t *info) {
1239
+ return bare_fs__lchown(env, info, bare_fs_async);
1240
+ }
1241
+
1242
+ static js_value_t *
1243
+ bare_fs_lchown_sync(js_env_t *env, js_callback_info_t *info) {
1244
+ return bare_fs__lchown(env, info, bare_fs_sync);
1245
+ }
1246
+
1247
+ static void
1248
+ bare_fs__on_fchown(uv_fs_t *handle) {
1249
+ bare_fs__on_request_result(handle);
1250
+ }
1251
+
1252
+ static inline js_value_t *
1253
+ bare_fs__fchown(js_env_t *env, js_callback_info_t *info, bool async) {
1254
+ int err;
1255
+
1256
+ size_t argc = 4;
1257
+ js_value_t *argv[4];
1258
+
1259
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1260
+ assert(err == 0);
1261
+
1262
+ assert(argc == 4);
1263
+
1264
+ bare_fs_req_t *req;
1265
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1266
+ assert(err == 0);
1267
+
1268
+ uint32_t fd;
1269
+ err = js_get_value_uint32(env, argv[1], &fd);
1270
+ assert(err == 0);
1271
+
1272
+ uint32_t uid;
1273
+ err = js_get_value_uint32(env, argv[2], &uid);
1274
+ assert(err == 0);
1275
+
1276
+ uint32_t gid;
1277
+ err = js_get_value_uint32(env, argv[3], &gid);
1278
+ assert(err == 0);
1279
+
1280
+ uv_loop_t *loop;
1281
+ err = js_get_env_loop(env, &loop);
1282
+ assert(err == 0);
1283
+
1284
+ err = uv_fs_fchown(loop, &req->handle, fd, uid, gid, async ? bare_fs__on_fchown : NULL);
1285
+ (void) err;
1286
+
1287
+ err = bare_fs__request_pending(env, req, async, NULL);
1288
+ (void) err;
1289
+
1290
+ return NULL;
1291
+ }
1292
+
1293
+ static js_value_t *
1294
+ bare_fs_fchown(js_env_t *env, js_callback_info_t *info) {
1295
+ return bare_fs__fchown(env, info, bare_fs_async);
1296
+ }
1297
+
1298
+ static js_value_t *
1299
+ bare_fs_fchown_sync(js_env_t *env, js_callback_info_t *info) {
1300
+ return bare_fs__fchown(env, info, bare_fs_sync);
1301
+ }
1302
+
1303
+ static void
1304
+ bare_fs__on_utimes(uv_fs_t *handle) {
1305
+ bare_fs__on_request_result(handle);
1306
+ }
1307
+
1308
+ static inline js_value_t *
1309
+ bare_fs__utimes(js_env_t *env, js_callback_info_t *info, bool async) {
1310
+ int err;
1311
+
1312
+ size_t argc = 4;
1313
+ js_value_t *argv[4];
1314
+
1315
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1316
+ assert(err == 0);
1317
+
1318
+ assert(argc == 4);
1319
+
1320
+ bare_fs_req_t *req;
1321
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1322
+ assert(err == 0);
1323
+
1324
+ bare_fs_path_t path;
1325
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1326
+ assert(err == 0);
1327
+
1328
+ double atime;
1329
+ err = js_get_value_double(env, argv[2], &atime);
1330
+ assert(err == 0);
1331
+
1332
+ double mtime;
1333
+ err = js_get_value_double(env, argv[3], &mtime);
1334
+ assert(err == 0);
1335
+
1336
+ uv_loop_t *loop;
1337
+ err = js_get_env_loop(env, &loop);
1338
+ assert(err == 0);
1339
+
1340
+ err = uv_fs_utime(loop, &req->handle, (char *) path, atime, mtime, async ? bare_fs__on_utimes : NULL);
1341
+ (void) err;
1342
+
1343
+ err = bare_fs__request_pending(env, req, async, NULL);
1344
+ (void) err;
1345
+
1346
+ return NULL;
1347
+ }
1348
+
1349
+ static js_value_t *
1350
+ bare_fs_utimes(js_env_t *env, js_callback_info_t *info) {
1351
+ return bare_fs__utimes(env, info, bare_fs_async);
1352
+ }
1353
+
1354
+ static js_value_t *
1355
+ bare_fs_utimes_sync(js_env_t *env, js_callback_info_t *info) {
1356
+ return bare_fs__utimes(env, info, bare_fs_sync);
1357
+ }
1358
+
1359
+ static void
1360
+ bare_fs__on_lutimes(uv_fs_t *handle) {
1361
+ bare_fs__on_request_result(handle);
1362
+ }
1363
+
1364
+ static inline js_value_t *
1365
+ bare_fs__lutimes(js_env_t *env, js_callback_info_t *info, bool async) {
1366
+ int err;
1367
+
1368
+ size_t argc = 4;
1369
+ js_value_t *argv[4];
1370
+
1371
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1372
+ assert(err == 0);
1373
+
1374
+ assert(argc == 4);
1375
+
1376
+ bare_fs_req_t *req;
1377
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1378
+ assert(err == 0);
1379
+
1380
+ bare_fs_path_t path;
1381
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1382
+ assert(err == 0);
1383
+
1384
+ double atime;
1385
+ err = js_get_value_double(env, argv[2], &atime);
1386
+ assert(err == 0);
1387
+
1388
+ double mtime;
1389
+ err = js_get_value_double(env, argv[3], &mtime);
1390
+ assert(err == 0);
1391
+
1392
+ uv_loop_t *loop;
1393
+ err = js_get_env_loop(env, &loop);
1394
+ assert(err == 0);
1395
+
1396
+ err = uv_fs_lutime(loop, &req->handle, (char *) path, atime, mtime, async ? bare_fs__on_lutimes : NULL);
1397
+ (void) err;
1398
+
1399
+ err = bare_fs__request_pending(env, req, async, NULL);
1400
+ (void) err;
1401
+
1402
+ return NULL;
1403
+ }
1404
+
1405
+ static js_value_t *
1406
+ bare_fs_lutimes(js_env_t *env, js_callback_info_t *info) {
1407
+ return bare_fs__lutimes(env, info, bare_fs_async);
1408
+ }
1409
+
1410
+ static js_value_t *
1411
+ bare_fs_lutimes_sync(js_env_t *env, js_callback_info_t *info) {
1412
+ return bare_fs__lutimes(env, info, bare_fs_sync);
1413
+ }
1414
+
1415
+ static void
1416
+ bare_fs__on_futimes(uv_fs_t *handle) {
1417
+ bare_fs__on_request_result(handle);
1418
+ }
1419
+
1420
+ static inline js_value_t *
1421
+ bare_fs__futimes(js_env_t *env, js_callback_info_t *info, bool async) {
1422
+ int err;
1423
+
1424
+ size_t argc = 4;
1425
+ js_value_t *argv[4];
1426
+
1427
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1428
+ assert(err == 0);
1429
+
1430
+ assert(argc == 4);
1431
+
1432
+ bare_fs_req_t *req;
1433
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1434
+ assert(err == 0);
1435
+
1436
+ uint32_t fd;
1437
+ err = js_get_value_uint32(env, argv[1], &fd);
1438
+ assert(err == 0);
1439
+
1440
+ double atime;
1441
+ err = js_get_value_double(env, argv[2], &atime);
1442
+ assert(err == 0);
1443
+
1444
+ double mtime;
1445
+ err = js_get_value_double(env, argv[3], &mtime);
1446
+ assert(err == 0);
1447
+
1448
+ uv_loop_t *loop;
1449
+ err = js_get_env_loop(env, &loop);
1450
+ assert(err == 0);
1451
+
1452
+ err = uv_fs_futime(loop, &req->handle, fd, atime, mtime, async ? bare_fs__on_futimes : NULL);
1453
+ (void) err;
1454
+
1455
+ err = bare_fs__request_pending(env, req, async, NULL);
1456
+ (void) err;
1457
+
1458
+ return NULL;
1459
+ }
1460
+
1461
+ static js_value_t *
1462
+ bare_fs_futimes(js_env_t *env, js_callback_info_t *info) {
1463
+ return bare_fs__futimes(env, info, bare_fs_async);
1464
+ }
1465
+
1466
+ static js_value_t *
1467
+ bare_fs_futimes_sync(js_env_t *env, js_callback_info_t *info) {
1468
+ return bare_fs__futimes(env, info, bare_fs_sync);
1469
+ }
1470
+
1471
+ static void
1472
+ bare_fs__on_rename(uv_fs_t *handle) {
1473
+ bare_fs__on_request_result(handle);
1474
+ }
1475
+
1476
+ static inline js_value_t *
1477
+ bare_fs__rename(js_env_t *env, js_callback_info_t *info, bool async) {
1478
+ int err;
1479
+
1480
+ size_t argc = 3;
1481
+ js_value_t *argv[3];
1482
+
1483
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1484
+ assert(err == 0);
1485
+
1486
+ assert(argc == 3);
1487
+
1488
+ bare_fs_req_t *req;
1489
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1490
+ assert(err == 0);
1491
+
1492
+ bare_fs_path_t src;
1493
+ err = js_get_value_string_utf8(env, argv[1], src, sizeof(bare_fs_path_t), NULL);
1494
+ assert(err == 0);
1495
+
1496
+ bare_fs_path_t dst;
1497
+ err = js_get_value_string_utf8(env, argv[2], dst, sizeof(bare_fs_path_t), NULL);
1498
+ assert(err == 0);
1499
+
1500
+ uv_loop_t *loop;
1501
+ err = js_get_env_loop(env, &loop);
1502
+ assert(err == 0);
1503
+
1504
+ err = uv_fs_rename(loop, &req->handle, (char *) src, (char *) dst, async ? bare_fs__on_rename : NULL);
1505
+ (void) err;
1506
+
1507
+ err = bare_fs__request_pending(env, req, async, NULL);
1508
+ (void) err;
1509
+
1510
+ return NULL;
1511
+ }
1512
+
1513
+ static js_value_t *
1514
+ bare_fs_rename(js_env_t *env, js_callback_info_t *info) {
1515
+ return bare_fs__rename(env, info, bare_fs_async);
1516
+ }
1517
+
1518
+ static js_value_t *
1519
+ bare_fs_rename_sync(js_env_t *env, js_callback_info_t *info) {
1520
+ return bare_fs__rename(env, info, bare_fs_sync);
1521
+ }
1522
+
1523
+ static void
1524
+ bare_fs__on_copyfile(uv_fs_t *handle) {
1525
+ bare_fs__on_request_result(handle);
1526
+ }
1527
+
1528
+ static inline js_value_t *
1529
+ bare_fs__copyfile(js_env_t *env, js_callback_info_t *info, bool async) {
1530
+ int err;
1531
+
1532
+ size_t argc = 4;
1533
+ js_value_t *argv[4];
1534
+
1535
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1536
+ assert(err == 0);
1537
+
1538
+ assert(argc == 4);
1539
+
1540
+ bare_fs_req_t *req;
1541
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1542
+ assert(err == 0);
1543
+
1544
+ bare_fs_path_t src;
1545
+ err = js_get_value_string_utf8(env, argv[1], src, sizeof(bare_fs_path_t), NULL);
1546
+ assert(err == 0);
1547
+
1548
+ bare_fs_path_t dst;
1549
+ err = js_get_value_string_utf8(env, argv[2], dst, sizeof(bare_fs_path_t), NULL);
1550
+ assert(err == 0);
1551
+
1552
+ int32_t mode;
1553
+ err = js_get_value_int32(env, argv[3], &mode);
1554
+ assert(err == 0);
1555
+
1556
+ uv_loop_t *loop;
1557
+ err = js_get_env_loop(env, &loop);
1558
+ assert(err == 0);
1559
+
1560
+ err = uv_fs_copyfile(loop, &req->handle, (char *) src, (char *) dst, mode, async ? bare_fs__on_copyfile : NULL);
1561
+ (void) err;
1562
+
1563
+ err = bare_fs__request_pending(env, req, async, NULL);
1564
+ (void) err;
1565
+
1566
+ return NULL;
1567
+ }
1568
+
1569
+ static js_value_t *
1570
+ bare_fs_copyfile(js_env_t *env, js_callback_info_t *info) {
1571
+ return bare_fs__copyfile(env, info, bare_fs_async);
1572
+ }
1573
+
1574
+ static js_value_t *
1575
+ bare_fs_copyfile_sync(js_env_t *env, js_callback_info_t *info) {
1576
+ return bare_fs__copyfile(env, info, bare_fs_sync);
1577
+ }
1578
+
1579
+ static void
1580
+ bare_fs__on_mkdir(uv_fs_t *handle) {
1581
+ bare_fs__on_request_result(handle);
1582
+ }
1583
+
1584
+ static inline js_value_t *
1585
+ bare_fs__mkdir(js_env_t *env, js_callback_info_t *info, bool async) {
1586
+ int err;
1587
+
1588
+ size_t argc = 3;
1589
+ js_value_t *argv[3];
1590
+
1591
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1592
+ assert(err == 0);
1593
+
1594
+ assert(argc == 3);
1595
+
1596
+ bare_fs_req_t *req;
1597
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1598
+ assert(err == 0);
1599
+
1600
+ bare_fs_path_t path;
1601
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1602
+ assert(err == 0);
1603
+
1604
+ int32_t mode;
1605
+ err = js_get_value_int32(env, argv[2], &mode);
1606
+ assert(err == 0);
1607
+
1608
+ uv_loop_t *loop;
1609
+ err = js_get_env_loop(env, &loop);
1610
+ assert(err == 0);
1611
+
1612
+ err = uv_fs_mkdir(loop, &req->handle, (char *) path, mode, async ? bare_fs__on_mkdir : NULL);
1613
+ (void) err;
1614
+
1615
+ err = bare_fs__request_pending(env, req, async, NULL);
1616
+ (void) err;
1617
+
1618
+ return NULL;
1619
+ }
1620
+
1621
+ static js_value_t *
1622
+ bare_fs_mkdir(js_env_t *env, js_callback_info_t *info) {
1623
+ return bare_fs__mkdir(env, info, bare_fs_async);
1624
+ }
1625
+
1626
+ static js_value_t *
1627
+ bare_fs_mkdir_sync(js_env_t *env, js_callback_info_t *info) {
1628
+ return bare_fs__mkdir(env, info, bare_fs_sync);
1629
+ }
1630
+
1631
+ static void
1632
+ bare_fs__on_mkdtemp(uv_fs_t *handle) {
1633
+ bare_fs__on_request_result(handle);
1634
+ }
1635
+
1636
+ static inline js_value_t *
1637
+ bare_fs__mkdtemp(js_env_t *env, js_callback_info_t *info, bool async) {
1638
+ int err;
1639
+
1640
+ size_t argc = 2;
1641
+ js_value_t *argv[2];
1642
+
1643
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1644
+ assert(err == 0);
1645
+
1646
+ assert(argc == 2);
1647
+
1648
+ bare_fs_req_t *req;
1649
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1650
+ assert(err == 0);
1651
+
1652
+ bare_fs_path_t prefix;
1653
+ err = js_get_value_string_utf8(env, argv[1], prefix, sizeof(bare_fs_path_t), NULL);
1654
+ assert(err == 0);
1655
+
1656
+ uv_loop_t *loop;
1657
+ err = js_get_env_loop(env, &loop);
1658
+ assert(err == 0);
1659
+
1660
+ err = uv_fs_mkdtemp(loop, &req->handle, (char *) prefix, async ? bare_fs__on_mkdtemp : NULL);
1661
+ (void) err;
1662
+
1663
+ err = bare_fs__request_pending(env, req, async, NULL);
1664
+ (void) err;
1665
+
1666
+ return NULL;
1667
+ }
1668
+
1669
+ static js_value_t *
1670
+ bare_fs_mkdtemp(js_env_t *env, js_callback_info_t *info) {
1671
+ return bare_fs__mkdtemp(env, info, bare_fs_async);
1672
+ }
1673
+
1674
+ static js_value_t *
1675
+ bare_fs_mkdtemp_sync(js_env_t *env, js_callback_info_t *info) {
1676
+ return bare_fs__mkdtemp(env, info, bare_fs_sync);
1677
+ }
1678
+
1679
+ static void
1680
+ bare_fs__on_link(uv_fs_t *handle) {
1681
+ bare_fs__on_request_result(handle);
1682
+ }
1683
+
1684
+ static inline js_value_t *
1685
+ bare_fs__link(js_env_t *env, js_callback_info_t *info, bool async) {
1686
+ int err;
1687
+
1688
+ size_t argc = 3;
1689
+ js_value_t *argv[3];
1690
+
1691
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1692
+ assert(err == 0);
1693
+
1694
+ assert(argc == 3);
1695
+
1696
+ bare_fs_req_t *req;
1697
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1698
+ assert(err == 0);
1699
+
1700
+ bare_fs_path_t src;
1701
+ err = js_get_value_string_utf8(env, argv[1], src, sizeof(bare_fs_path_t), NULL);
1702
+ assert(err == 0);
1703
+
1704
+ bare_fs_path_t dst;
1705
+ err = js_get_value_string_utf8(env, argv[2], dst, sizeof(bare_fs_path_t), NULL);
1706
+ assert(err == 0);
1707
+
1708
+ uv_loop_t *loop;
1709
+ err = js_get_env_loop(env, &loop);
1710
+ assert(err == 0);
1711
+
1712
+ err = uv_fs_link(loop, &req->handle, (char *) src, (char *) dst, async ? bare_fs__on_link : NULL);
1713
+ (void) err;
1714
+
1715
+ err = bare_fs__request_pending(env, req, async, NULL);
1716
+ (void) err;
1717
+
1718
+ return NULL;
1719
+ }
1720
+
1721
+ static js_value_t *
1722
+ bare_fs_link(js_env_t *env, js_callback_info_t *info) {
1723
+ return bare_fs__link(env, info, bare_fs_async);
1724
+ }
1725
+
1726
+ static js_value_t *
1727
+ bare_fs_link_sync(js_env_t *env, js_callback_info_t *info) {
1728
+ return bare_fs__link(env, info, bare_fs_sync);
1729
+ }
1730
+
1731
+ static void
1732
+ bare_fs__on_rmdir(uv_fs_t *handle) {
1733
+ bare_fs__on_request_result(handle);
1734
+ }
1735
+
1736
+ static inline js_value_t *
1737
+ bare_fs__rmdir(js_env_t *env, js_callback_info_t *info, bool async) {
1738
+ int err;
1739
+
1740
+ size_t argc = 2;
1741
+ js_value_t *argv[2];
1742
+
1743
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1744
+ assert(err == 0);
1745
+
1746
+ assert(argc == 2);
1747
+
1748
+ bare_fs_req_t *req;
1749
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1750
+ assert(err == 0);
1751
+
1752
+ bare_fs_path_t path;
1753
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1754
+ assert(err == 0);
1755
+
1756
+ uv_loop_t *loop;
1757
+ err = js_get_env_loop(env, &loop);
1758
+ assert(err == 0);
1759
+
1760
+ err = uv_fs_rmdir(loop, &req->handle, (char *) path, async ? bare_fs__on_rmdir : NULL);
1761
+ (void) err;
1762
+
1763
+ err = bare_fs__request_pending(env, req, async, NULL);
1764
+ (void) err;
1765
+
1766
+ return NULL;
1767
+ }
1768
+
1769
+ static js_value_t *
1770
+ bare_fs_rmdir(js_env_t *env, js_callback_info_t *info) {
1771
+ return bare_fs__rmdir(env, info, bare_fs_async);
1772
+ }
1773
+
1774
+ static js_value_t *
1775
+ bare_fs_rmdir_sync(js_env_t *env, js_callback_info_t *info) {
1776
+ return bare_fs__rmdir(env, info, bare_fs_sync);
1777
+ }
1778
+
1779
+ static void
1780
+ bare_fs__on_stat(uv_fs_t *handle) {
1781
+ bare_fs__on_request_result(handle);
1782
+ }
1783
+
1784
+ static inline js_value_t *
1785
+ bare_fs__stat(js_env_t *env, js_callback_info_t *info, bool async) {
1786
+ int err;
1787
+
1788
+ size_t argc = 2;
1789
+ js_value_t *argv[2];
1790
+
1791
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1792
+ assert(err == 0);
1793
+
1794
+ assert(argc == 2);
1795
+
1796
+ bare_fs_req_t *req;
1797
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1798
+ assert(err == 0);
1799
+
1800
+ bare_fs_path_t path;
1801
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1802
+ assert(err == 0);
1803
+
1804
+ uv_loop_t *loop;
1805
+ err = js_get_env_loop(env, &loop);
1806
+ assert(err == 0);
1807
+
1808
+ err = uv_fs_stat(loop, &req->handle, (char *) path, async ? bare_fs__on_stat : NULL);
1809
+ (void) err;
1810
+
1811
+ err = bare_fs__request_pending(env, req, async, NULL);
1812
+ (void) err;
1813
+
1814
+ return NULL;
1815
+ }
1816
+
1817
+ static js_value_t *
1818
+ bare_fs_stat(js_env_t *env, js_callback_info_t *info) {
1819
+ return bare_fs__stat(env, info, bare_fs_async);
1820
+ }
1821
+
1822
+ static js_value_t *
1823
+ bare_fs_stat_sync(js_env_t *env, js_callback_info_t *info) {
1824
+ return bare_fs__stat(env, info, bare_fs_sync);
1825
+ }
1826
+
1827
+ static void
1828
+ bare_fs__on_lstat(uv_fs_t *handle) {
1829
+ bare_fs__on_request_result(handle);
1830
+ }
1831
+
1832
+ static inline js_value_t *
1833
+ bare_fs__lstat(js_env_t *env, js_callback_info_t *info, bool async) {
1834
+ int err;
1835
+
1836
+ size_t argc = 2;
1837
+ js_value_t *argv[2];
1838
+
1839
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1840
+ assert(err == 0);
1841
+
1842
+ assert(argc == 2);
1843
+
1844
+ bare_fs_req_t *req;
1845
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1846
+ assert(err == 0);
1847
+
1848
+ bare_fs_path_t path;
1849
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1850
+ assert(err == 0);
1851
+
1852
+ uv_loop_t *loop;
1853
+ err = js_get_env_loop(env, &loop);
1854
+ assert(err == 0);
1855
+
1856
+ err = uv_fs_lstat(loop, &req->handle, (char *) path, async ? bare_fs__on_lstat : NULL);
1857
+ (void) err;
1858
+
1859
+ err = bare_fs__request_pending(env, req, async, NULL);
1860
+ (void) err;
1861
+
1862
+ return NULL;
1863
+ }
1864
+
1865
+ static js_value_t *
1866
+ bare_fs_lstat(js_env_t *env, js_callback_info_t *info) {
1867
+ return bare_fs__lstat(env, info, bare_fs_async);
1868
+ }
1869
+
1870
+ static js_value_t *
1871
+ bare_fs_lstat_sync(js_env_t *env, js_callback_info_t *info) {
1872
+ return bare_fs__lstat(env, info, bare_fs_sync);
1873
+ }
1874
+
1875
+ static void
1876
+ bare_fs__on_fstat(uv_fs_t *handle) {
1877
+ bare_fs__on_request_result(handle);
1878
+ }
1879
+
1880
+ static inline js_value_t *
1881
+ bare_fs__fstat(js_env_t *env, js_callback_info_t *info, bool async) {
1882
+ int err;
1883
+
1884
+ size_t argc = 2;
1885
+ js_value_t *argv[2];
1886
+
1887
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1888
+ assert(err == 0);
1889
+
1890
+ assert(argc == 2);
1891
+
1892
+ bare_fs_req_t *req;
1893
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1894
+ assert(err == 0);
1895
+
1896
+ uint32_t fd;
1897
+ err = js_get_value_uint32(env, argv[1], &fd);
1898
+ assert(err == 0);
1899
+
1900
+ uv_loop_t *loop;
1901
+ err = js_get_env_loop(env, &loop);
1902
+ assert(err == 0);
1903
+
1904
+ err = uv_fs_fstat(loop, &req->handle, fd, async ? bare_fs__on_fstat : NULL);
1905
+ (void) err;
1906
+
1907
+ err = bare_fs__request_pending(env, req, async, NULL);
1908
+ (void) err;
1909
+
1910
+ return NULL;
1911
+ }
1912
+
1913
+ static js_value_t *
1914
+ bare_fs_fstat(js_env_t *env, js_callback_info_t *info) {
1915
+ return bare_fs__fstat(env, info, bare_fs_async);
1916
+ }
1917
+
1918
+ static js_value_t *
1919
+ bare_fs_fstat_sync(js_env_t *env, js_callback_info_t *info) {
1920
+ return bare_fs__fstat(env, info, bare_fs_sync);
1921
+ }
1922
+
1923
+ static void
1924
+ bare_fs__on_statfs(uv_fs_t *handle) {
1925
+ bare_fs__on_request_result(handle);
1926
+ }
1927
+
1928
+ static inline js_value_t *
1929
+ bare_fs__statfs(js_env_t *env, js_callback_info_t *info, bool async) {
1930
+ int err;
1931
+
1932
+ size_t argc = 2;
1933
+ js_value_t *argv[2];
1934
+
1935
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1936
+ assert(err == 0);
1937
+
1938
+ assert(argc == 2);
1939
+
1940
+ bare_fs_req_t *req;
1941
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1942
+ assert(err == 0);
1943
+
1944
+ bare_fs_path_t path;
1945
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1946
+ assert(err == 0);
1947
+
1948
+ uv_loop_t *loop;
1949
+ err = js_get_env_loop(env, &loop);
1950
+ assert(err == 0);
1951
+
1952
+ err = uv_fs_statfs(loop, &req->handle, (char *) path, async ? bare_fs__on_statfs : NULL);
1953
+ (void) err;
1954
+
1955
+ err = bare_fs__request_pending(env, req, async, NULL);
1956
+ (void) err;
1957
+
1958
+ return NULL;
1959
+ }
1960
+
1961
+ static js_value_t *
1962
+ bare_fs_statfs(js_env_t *env, js_callback_info_t *info) {
1963
+ return bare_fs__statfs(env, info, bare_fs_async);
1964
+ }
1965
+
1966
+ static js_value_t *
1967
+ bare_fs_statfs_sync(js_env_t *env, js_callback_info_t *info) {
1968
+ return bare_fs__statfs(env, info, bare_fs_sync);
1969
+ }
1970
+
1971
+ static void
1972
+ bare_fs__on_unlink(uv_fs_t *handle) {
1973
+ bare_fs__on_request_result(handle);
1974
+ }
1975
+
1976
+ static inline js_value_t *
1977
+ bare_fs__unlink(js_env_t *env, js_callback_info_t *info, bool async) {
1978
+ int err;
1979
+
1980
+ size_t argc = 2;
1981
+ js_value_t *argv[2];
1982
+
1983
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1984
+ assert(err == 0);
1985
+
1986
+ assert(argc == 2);
1987
+
1988
+ bare_fs_req_t *req;
1989
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
1990
+ assert(err == 0);
1991
+
1992
+ bare_fs_path_t path;
1993
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
1994
+ assert(err == 0);
1995
+
1996
+ uv_loop_t *loop;
1997
+ err = js_get_env_loop(env, &loop);
1998
+ assert(err == 0);
1999
+
2000
+ err = uv_fs_unlink(loop, &req->handle, (char *) path, async ? bare_fs__on_unlink : NULL);
2001
+ (void) err;
2002
+
2003
+ err = bare_fs__request_pending(env, req, async, NULL);
2004
+ (void) err;
2005
+
2006
+ return NULL;
2007
+ }
2008
+
2009
+ static js_value_t *
2010
+ bare_fs_unlink(js_env_t *env, js_callback_info_t *info) {
2011
+ return bare_fs__unlink(env, info, bare_fs_async);
2012
+ }
2013
+
2014
+ static js_value_t *
2015
+ bare_fs_unlink_sync(js_env_t *env, js_callback_info_t *info) {
2016
+ return bare_fs__unlink(env, info, bare_fs_sync);
2017
+ }
2018
+
2019
+ static void
2020
+ bare_fs__on_realpath(uv_fs_t *handle) {
2021
+ bare_fs__on_request_result(handle);
2022
+ }
2023
+
2024
+ static inline js_value_t *
2025
+ bare_fs__realpath(js_env_t *env, js_callback_info_t *info, bool async) {
2026
+ int err;
2027
+
2028
+ size_t argc = 2;
2029
+ js_value_t *argv[2];
2030
+
2031
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2032
+ assert(err == 0);
2033
+
2034
+ assert(argc == 2);
2035
+
2036
+ bare_fs_req_t *req;
2037
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2038
+ assert(err == 0);
2039
+
2040
+ bare_fs_path_t path;
2041
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
2042
+ assert(err == 0);
2043
+
2044
+ uv_loop_t *loop;
2045
+ err = js_get_env_loop(env, &loop);
2046
+ assert(err == 0);
2047
+
2048
+ err = uv_fs_realpath(loop, &req->handle, (char *) path, async ? bare_fs__on_realpath : NULL);
2049
+ (void) err;
2050
+
2051
+ err = bare_fs__request_pending(env, req, async, NULL);
2052
+ (void) err;
2053
+
2054
+ return NULL;
2055
+ }
2056
+
2057
+ static js_value_t *
2058
+ bare_fs_realpath(js_env_t *env, js_callback_info_t *info) {
2059
+ return bare_fs__realpath(env, info, bare_fs_async);
2060
+ }
2061
+
2062
+ static js_value_t *
2063
+ bare_fs_realpath_sync(js_env_t *env, js_callback_info_t *info) {
2064
+ return bare_fs__realpath(env, info, bare_fs_sync);
2065
+ }
2066
+
2067
+ static void
2068
+ bare_fs__on_readlink(uv_fs_t *handle) {
2069
+ bare_fs__on_request_result(handle);
2070
+ }
2071
+
2072
+ static inline js_value_t *
2073
+ bare_fs__readlink(js_env_t *env, js_callback_info_t *info, bool async) {
2074
+ int err;
2075
+
2076
+ size_t argc = 2;
2077
+ js_value_t *argv[2];
2078
+
2079
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2080
+ assert(err == 0);
2081
+
2082
+ assert(argc == 2);
2083
+
2084
+ bare_fs_req_t *req;
2085
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2086
+ assert(err == 0);
2087
+
2088
+ bare_fs_path_t path;
2089
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
2090
+ assert(err == 0);
2091
+
2092
+ uv_loop_t *loop;
2093
+ err = js_get_env_loop(env, &loop);
2094
+ assert(err == 0);
2095
+
2096
+ err = uv_fs_readlink(loop, &req->handle, (char *) path, async ? bare_fs__on_readlink : NULL);
2097
+ (void) err;
2098
+
2099
+ err = bare_fs__request_pending(env, req, async, NULL);
2100
+ (void) err;
2101
+
2102
+ return NULL;
2103
+ }
2104
+
2105
+ static js_value_t *
2106
+ bare_fs_readlink(js_env_t *env, js_callback_info_t *info) {
2107
+ return bare_fs__readlink(env, info, bare_fs_async);
2108
+ }
2109
+
2110
+ static js_value_t *
2111
+ bare_fs_readlink_sync(js_env_t *env, js_callback_info_t *info) {
2112
+ return bare_fs__readlink(env, info, bare_fs_sync);
2113
+ }
2114
+
2115
+ static void
2116
+ bare_fs__on_symlink(uv_fs_t *handle) {
2117
+ bare_fs__on_request_result(handle);
2118
+ }
2119
+
2120
+ static inline js_value_t *
2121
+ bare_fs__symlink(js_env_t *env, js_callback_info_t *info, bool async) {
2122
+ int err;
2123
+
2124
+ size_t argc = 4;
2125
+ js_value_t *argv[4];
2126
+
2127
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2128
+ assert(err == 0);
2129
+
2130
+ assert(argc == 4);
2131
+
2132
+ bare_fs_req_t *req;
2133
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2134
+ assert(err == 0);
2135
+
2136
+ bare_fs_path_t target;
2137
+ err = js_get_value_string_utf8(env, argv[1], target, sizeof(bare_fs_path_t), NULL);
2138
+ assert(err == 0);
2139
+
2140
+ bare_fs_path_t path;
2141
+ err = js_get_value_string_utf8(env, argv[2], path, sizeof(bare_fs_path_t), NULL);
2142
+ assert(err == 0);
2143
+
2144
+ int32_t flags;
2145
+ err = js_get_value_int32(env, argv[3], &flags);
2146
+ assert(err == 0);
2147
+
2148
+ uv_loop_t *loop;
2149
+ err = js_get_env_loop(env, &loop);
2150
+ assert(err == 0);
2151
+
2152
+ err = uv_fs_symlink(loop, &req->handle, (char *) target, (char *) path, flags, async ? bare_fs__on_symlink : NULL);
2153
+ (void) err;
2154
+
2155
+ err = bare_fs__request_pending(env, req, async, NULL);
2156
+ (void) err;
2157
+
2158
+ return NULL;
2159
+ }
2160
+
2161
+ static js_value_t *
2162
+ bare_fs_symlink(js_env_t *env, js_callback_info_t *info) {
2163
+ return bare_fs__symlink(env, info, bare_fs_async);
2164
+ }
2165
+
2166
+ static js_value_t *
2167
+ bare_fs_symlink_sync(js_env_t *env, js_callback_info_t *info) {
2168
+ return bare_fs__symlink(env, info, bare_fs_sync);
2169
+ }
2170
+
2171
+ static void
2172
+ bare_fs__on_opendir(uv_fs_t *handle) {
2173
+ int err;
2174
+
2175
+ bare_fs_req_t *req = (bare_fs_req_t *) handle;
2176
+
2177
+ int status = handle->result;
2178
+
2179
+ if (req->exiting && status >= 0) {
2180
+ uv_dir_t *dir = handle->ptr;
2181
+
2182
+ uv_fs_req_cleanup(handle);
2183
+
2184
+ err = uv_fs_closedir(handle->loop, handle, dir, NULL);
2185
+ assert(err == 0);
2186
+ }
2187
+
2188
+ bare_fs__on_request_result(handle);
2189
+ }
2190
+
2191
+ static inline js_value_t *
2192
+ bare_fs__opendir(js_env_t *env, js_callback_info_t *info, bool async) {
2193
+ int err;
2194
+
2195
+ size_t argc = 2;
2196
+ js_value_t *argv[2];
2197
+
2198
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2199
+ assert(err == 0);
2200
+
2201
+ assert(argc == 2);
2202
+
2203
+ bare_fs_req_t *req;
2204
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2205
+ assert(err == 0);
2206
+
2207
+ bare_fs_path_t path;
2208
+ err = js_get_value_string_utf8(env, argv[1], path, sizeof(bare_fs_path_t), NULL);
2209
+ assert(err == 0);
2210
+
2211
+ uv_loop_t *loop;
2212
+ err = js_get_env_loop(env, &loop);
2213
+ assert(err == 0);
2214
+
2215
+ err = uv_fs_opendir(loop, &req->handle, (char *) path, async ? bare_fs__on_opendir : NULL);
2216
+ (void) err;
2217
+
2218
+ err = bare_fs__request_pending(env, req, async, NULL);
2219
+ (void) err;
2220
+
2221
+ return NULL;
2222
+ }
2223
+
2224
+ static js_value_t *
2225
+ bare_fs_opendir(js_env_t *env, js_callback_info_t *info) {
2226
+ return bare_fs__opendir(env, info, bare_fs_async);
2227
+ }
2228
+
2229
+ static js_value_t *
2230
+ bare_fs_opendir_sync(js_env_t *env, js_callback_info_t *info) {
2231
+ return bare_fs__opendir(env, info, bare_fs_sync);
2232
+ }
2233
+
2234
+ static void
2235
+ bare_fs__on_readdir(uv_fs_t *handle) {
2236
+ bare_fs__on_request_result(handle);
2237
+ }
2238
+
2239
+ static inline js_value_t *
2240
+ bare_fs__readdir(js_env_t *env, js_callback_info_t *info, bool async) {
2241
+ int err;
2242
+
2243
+ size_t argc = 3;
2244
+ js_value_t *argv[3];
2245
+
2246
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2247
+ assert(err == 0);
2248
+
2249
+ assert(argc == 3);
2250
+
2251
+ bare_fs_req_t *req;
2252
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2253
+ assert(err == 0);
2254
+
2255
+ bare_fs_dir_t *dir;
2256
+ err = js_get_arraybuffer_info(env, argv[1], (void **) &dir, NULL);
2257
+ assert(err == 0);
2258
+
2259
+ uint32_t capacity;
2260
+ err = js_get_value_uint32(env, argv[2], &capacity);
2261
+ assert(err == 0);
2262
+
2263
+ js_value_t *result;
2264
+
2265
+ bare_fs_dirent_t *dirents;
2266
+ err = js_create_arraybuffer(env, capacity * sizeof(bare_fs_dirent_t), (void **) &dirents, &result);
2267
+ assert(err == 0);
2268
+
2269
+ uv_loop_t *loop;
2270
+ err = js_get_env_loop(env, &loop);
2271
+ assert(err == 0);
2272
+
2273
+ dir->handle->dirents = dirents;
2274
+ dir->handle->nentries = capacity;
2275
+
2276
+ err = uv_fs_readdir(loop, &req->handle, dir->handle, async ? bare_fs__on_readdir : NULL);
2277
+ (void) err;
2278
+
2279
+ err = bare_fs__request_pending(env, req, async, NULL);
2280
+ (void) err;
2281
+
2282
+ return result;
2283
+ }
2284
+
2285
+ static js_value_t *
2286
+ bare_fs_readdir(js_env_t *env, js_callback_info_t *info) {
2287
+ return bare_fs__readdir(env, info, bare_fs_async);
2288
+ }
2289
+
2290
+ static js_value_t *
2291
+ bare_fs_readdir_sync(js_env_t *env, js_callback_info_t *info) {
2292
+ return bare_fs__readdir(env, info, bare_fs_sync);
2293
+ }
2294
+
2295
+ static void
2296
+ bare_fs__on_closedir(uv_fs_t *handle) {
2297
+ bare_fs__on_request_result(handle);
2298
+ }
2299
+
2300
+ static inline js_value_t *
2301
+ bare_fs__closedir(js_env_t *env, js_callback_info_t *info, bool async) {
2302
+ int err;
2303
+
2304
+ size_t argc = 2;
2305
+ js_value_t *argv[2];
2306
+
2307
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2308
+ assert(err == 0);
2309
+
2310
+ assert(argc == 2);
2311
+
2312
+ bare_fs_req_t *req;
2313
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2314
+ assert(err == 0);
2315
+
2316
+ bare_fs_dir_t *dir;
2317
+ err = js_get_arraybuffer_info(env, argv[1], (void **) &dir, NULL);
2318
+ assert(err == 0);
2319
+
2320
+ uv_loop_t *loop;
2321
+ err = js_get_env_loop(env, &loop);
2322
+ assert(err == 0);
2323
+
2324
+ err = uv_fs_closedir(loop, &req->handle, dir->handle, async ? bare_fs__on_closedir : NULL);
2325
+ (void) err;
2326
+
2327
+ err = bare_fs__request_pending(env, req, async, NULL);
2328
+ (void) err;
2329
+
2330
+ return NULL;
2331
+ }
2332
+
2333
+ static js_value_t *
2334
+ bare_fs_closedir(js_env_t *env, js_callback_info_t *info) {
2335
+ return bare_fs__closedir(env, info, bare_fs_async);
2336
+ }
2337
+
2338
+ static js_value_t *
2339
+ bare_fs_closedir_sync(js_env_t *env, js_callback_info_t *info) {
2340
+ return bare_fs__closedir(env, info, bare_fs_sync);
2341
+ }
2342
+
2343
+ static void
2344
+ bare_fs__on_fsync(uv_fs_t *handle) {
2345
+ bare_fs__on_request_result(handle);
2346
+ }
2347
+
2348
+ static inline js_value_t *
2349
+ bare_fs__fsync(js_env_t *env, js_callback_info_t *info, bool async) {
2350
+ int err;
2351
+
2352
+ size_t argc = 2;
2353
+ js_value_t *argv[2];
2354
+
2355
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2356
+ assert(err == 0);
2357
+
2358
+ assert(argc == 2);
2359
+
2360
+ bare_fs_req_t *req;
2361
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2362
+ assert(err == 0);
2363
+
2364
+ uint32_t fd;
2365
+ err = js_get_value_uint32(env, argv[1], &fd);
2366
+ assert(err == 0);
2367
+
2368
+ uv_loop_t *loop;
2369
+ err = js_get_env_loop(env, &loop);
2370
+ assert(err == 0);
2371
+
2372
+ err = uv_fs_fsync(loop, &req->handle, fd, async ? bare_fs__on_fsync : NULL);
2373
+ (void) err;
2374
+
2375
+ err = bare_fs__request_pending(env, req, async, NULL);
2376
+ (void) err;
2377
+
2378
+ return NULL;
2379
+ }
2380
+
2381
+ static js_value_t *
2382
+ bare_fs_fsync(js_env_t *env, js_callback_info_t *info) {
2383
+ return bare_fs__fsync(env, info, bare_fs_async);
2384
+ }
2385
+
2386
+ static js_value_t *
2387
+ bare_fs_fsync_sync(js_env_t *env, js_callback_info_t *info) {
2388
+ return bare_fs__fsync(env, info, bare_fs_sync);
2389
+ }
2390
+
2391
+ static void
2392
+ bare_fs__on_fdatasync(uv_fs_t *handle) {
2393
+ bare_fs__on_request_result(handle);
2394
+ }
2395
+
2396
+ static inline js_value_t *
2397
+ bare_fs__fdatasync(js_env_t *env, js_callback_info_t *info, bool async) {
2398
+ int err;
2399
+
2400
+ size_t argc = 2;
2401
+ js_value_t *argv[2];
2402
+
2403
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2404
+ assert(err == 0);
2405
+
2406
+ assert(argc == 2);
2407
+
2408
+ bare_fs_req_t *req;
2409
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &req, NULL);
2410
+ assert(err == 0);
2411
+
2412
+ uint32_t fd;
2413
+ err = js_get_value_uint32(env, argv[1], &fd);
2414
+ assert(err == 0);
2415
+
2416
+ uv_loop_t *loop;
2417
+ err = js_get_env_loop(env, &loop);
2418
+ assert(err == 0);
2419
+
2420
+ err = uv_fs_fdatasync(loop, &req->handle, fd, async ? bare_fs__on_fdatasync : NULL);
2421
+ (void) err;
2422
+
2423
+ err = bare_fs__request_pending(env, req, async, NULL);
2424
+ (void) err;
2425
+
2426
+ return NULL;
2427
+ }
2428
+
2429
+ static js_value_t *
2430
+ bare_fs_fdatasync(js_env_t *env, js_callback_info_t *info) {
2431
+ return bare_fs__fdatasync(env, info, bare_fs_async);
2432
+ }
2433
+
2434
+ static js_value_t *
2435
+ bare_fs_fdatasync_sync(js_env_t *env, js_callback_info_t *info) {
2436
+ return bare_fs__fdatasync(env, info, bare_fs_sync);
2437
+ }
2438
+
2439
+ static void
2440
+ bare_fs__on_watcher_event(uv_fs_event_t *handle, const char *filename, int events, int status) {
2441
+ int err;
2442
+
2443
+ bare_fs_watcher_t *watcher = (bare_fs_watcher_t *) handle;
2444
+
2445
+ if (watcher->exiting) return;
2446
+
2447
+ js_env_t *env = watcher->env;
2448
+
2449
+ js_handle_scope_t *scope;
2450
+ err = js_open_handle_scope(env, &scope);
2451
+ assert(err == 0);
2452
+
2453
+ js_value_t *ctx;
2454
+ err = js_get_reference_value(env, watcher->ctx, &ctx);
2455
+ assert(err == 0);
2456
+
2457
+ js_value_t *on_event;
2458
+ err = js_get_reference_value(env, watcher->on_event, &on_event);
2459
+ assert(err == 0);
2460
+
2461
+ js_value_t *args[3];
2462
+
2463
+ if (status < 0) {
2464
+ js_value_t *code;
2465
+ err = js_create_string_utf8(env, (utf8_t *) uv_err_name(status), -1, &code);
2466
+ assert(err == 0);
2467
+
2468
+ js_value_t *message;
2469
+ err = js_create_string_utf8(env, (utf8_t *) uv_strerror(status), -1, &message);
2470
+ assert(err == 0);
2471
+
2472
+ err = js_create_error(env, code, message, &args[0]);
2473
+ assert(err == 0);
2474
+
2475
+ err = js_create_int32(env, 0, &args[1]);
2476
+ assert(err == 0);
2477
+
2478
+ err = js_get_null(env, &args[2]);
2479
+ assert(err == 0);
2480
+ } else {
2481
+ err = js_get_null(env, &args[0]);
2482
+ assert(err == 0);
2483
+
2484
+ err = js_create_int32(env, events, &args[1]);
2485
+ assert(err == 0);
2486
+
2487
+ size_t len = strlen(filename);
2488
+
2489
+ void *data;
2490
+ err = js_create_arraybuffer(env, len, &data, &args[2]);
2491
+ assert(err == 0);
2492
+
2493
+ memcpy(data, (void *) filename, len);
2494
+ }
2495
+
2496
+ err = js_call_function(env, ctx, on_event, 3, args, NULL);
2497
+ (void) err;
2498
+
2499
+ err = js_close_handle_scope(env, scope);
2500
+ assert(err == 0);
2501
+ }
2502
+
2503
+ static void
2504
+ bare_fs__on_watcher_close(uv_handle_t *handle) {
2505
+ int err;
2506
+
2507
+ bare_fs_watcher_t *watcher = (bare_fs_watcher_t *) handle;
2508
+
2509
+ js_env_t *env = watcher->env;
2510
+
2511
+ js_deferred_teardown_t *teardown = watcher->teardown;
2512
+
2513
+ if (watcher->exiting) {
2514
+ err = js_delete_reference(env, watcher->on_event);
2515
+ assert(err == 0);
2516
+
2517
+ err = js_delete_reference(env, watcher->on_close);
2518
+ assert(err == 0);
2519
+
2520
+ err = js_delete_reference(env, watcher->ctx);
2521
+ assert(err == 0);
2522
+ } else {
2523
+ js_handle_scope_t *scope;
2524
+ err = js_open_handle_scope(env, &scope);
2525
+ assert(err == 0);
2526
+
2527
+ js_value_t *ctx;
2528
+ err = js_get_reference_value(env, watcher->ctx, &ctx);
2529
+ assert(err == 0);
2530
+
2531
+ js_value_t *on_close;
2532
+ err = js_get_reference_value(env, watcher->on_close, &on_close);
2533
+ assert(err == 0);
2534
+
2535
+ err = js_delete_reference(env, watcher->on_event);
2536
+ assert(err == 0);
2537
+
2538
+ err = js_delete_reference(env, watcher->on_close);
2539
+ assert(err == 0);
2540
+
2541
+ err = js_delete_reference(env, watcher->ctx);
2542
+ assert(err == 0);
2543
+
2544
+ err = js_call_function(env, ctx, on_close, 0, NULL, NULL);
2545
+ (void) err;
2546
+
2547
+ err = js_close_handle_scope(env, scope);
2548
+ assert(err == 0);
2549
+ }
2550
+
2551
+ err = js_finish_deferred_teardown_callback(teardown);
2552
+ assert(err == 0);
2553
+ }
2554
+
2555
+ static void
2556
+ bare_fs__on_watcher_teardown(js_deferred_teardown_t *handle, void *data) {
2557
+ bare_fs_watcher_t *watcher = (bare_fs_watcher_t *) data;
2558
+
2559
+ watcher->exiting = true;
2560
+
2561
+ if (watcher->closing) return;
2562
+
2563
+ uv_close((uv_handle_t *) &watcher->handle, bare_fs__on_watcher_close);
2564
+ }
2565
+
2566
+ static js_value_t *
2567
+ bare_fs_watcher_init(js_env_t *env, js_callback_info_t *info) {
2568
+ int err;
2569
+
2570
+ size_t argc = 5;
2571
+ js_value_t *argv[5];
2572
+
2573
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2574
+ assert(err == 0);
2575
+
2576
+ assert(argc == 5);
2577
+
2578
+ bare_fs_path_t path;
2579
+ err = js_get_value_string_utf8(env, argv[0], path, sizeof(bare_fs_path_t), NULL);
2580
+ assert(err == 0);
2581
+
2582
+ bool recursive;
2583
+ err = js_get_value_bool(env, argv[1], &recursive);
2584
+ assert(err == 0);
2585
+
2586
+ js_value_t *result;
2587
+
2588
+ bare_fs_watcher_t *watcher;
2589
+ err = js_create_arraybuffer(env, sizeof(bare_fs_watcher_t), (void **) &watcher, &result);
2590
+ assert(err == 0);
2591
+
2592
+ uv_loop_t *loop;
2593
+ err = js_get_env_loop(env, &loop);
2594
+ assert(err == 0);
2595
+
2596
+ err = uv_fs_event_init(loop, &watcher->handle);
2597
+
2598
+ if (err < 0) {
2599
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
2600
+ assert(err == 0);
2601
+
2602
+ return NULL;
2603
+ }
2604
+
2605
+ err = uv_fs_event_start(&watcher->handle, bare_fs__on_watcher_event, (char *) path, recursive ? UV_FS_EVENT_RECURSIVE : 0);
2606
+ assert(err == 0);
2607
+
2608
+ watcher->env = env;
2609
+ watcher->closing = false;
2610
+ watcher->exiting = false;
2611
+
2612
+ err = js_create_reference(env, argv[2], 1, &watcher->ctx);
2613
+ assert(err == 0);
2614
+
2615
+ err = js_create_reference(env, argv[3], 1, &watcher->on_event);
2616
+ assert(err == 0);
2617
+
2618
+ err = js_create_reference(env, argv[4], 1, &watcher->on_close);
2619
+ assert(err == 0);
2620
+
2621
+ err = js_add_deferred_teardown_callback(env, bare_fs__on_watcher_teardown, (void *) watcher, &watcher->teardown);
2622
+ assert(err == 0);
2623
+
2624
+ return result;
2625
+ }
2626
+
2627
+ static js_value_t *
2628
+ bare_fs_watcher_close(js_env_t *env, js_callback_info_t *info) {
2629
+ int err;
2630
+
2631
+ size_t argc = 1;
2632
+ js_value_t *argv[1];
2633
+
2634
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2635
+ assert(err == 0);
2636
+
2637
+ assert(argc == 1);
2638
+
2639
+ bare_fs_watcher_t *watcher;
2640
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &watcher, NULL);
2641
+ assert(err == 0);
2642
+
2643
+ err = uv_fs_event_stop(&watcher->handle);
2644
+ assert(err == 0);
2645
+
2646
+ watcher->closing = true;
2647
+
2648
+ uv_close((uv_handle_t *) &watcher->handle, bare_fs__on_watcher_close);
2649
+
2650
+ return NULL;
2651
+ }
2652
+
2653
+ static js_value_t *
2654
+ bare_fs_watcher_ref(js_env_t *env, js_callback_info_t *info) {
2655
+ int err;
2656
+
2657
+ size_t argc = 1;
2658
+ js_value_t *argv[1];
2659
+
2660
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2661
+ assert(err == 0);
2662
+
2663
+ assert(argc == 1);
2664
+
2665
+ bare_fs_watcher_t *watcher;
2666
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &watcher, NULL);
2667
+ assert(err == 0);
2668
+
2669
+ uv_ref((uv_handle_t *) &watcher->handle);
2670
+
2671
+ return NULL;
2672
+ }
2673
+
2674
+ static js_value_t *
2675
+ bare_fs_watcher_unref(js_env_t *env, js_callback_info_t *info) {
2676
+ int err;
2677
+
2678
+ size_t argc = 1;
2679
+ js_value_t *argv[1];
2680
+
2681
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
2682
+ assert(err == 0);
2683
+
2684
+ assert(argc == 1);
2685
+
2686
+ bare_fs_watcher_t *watcher;
2687
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &watcher, NULL);
2688
+ assert(err == 0);
2689
+
2690
+ uv_unref((uv_handle_t *) &watcher->handle);
2691
+
2692
+ return NULL;
2693
+ }
2694
+
2695
+ static js_value_t *
2696
+ bare_fs_exports(js_env_t *env, js_value_t *exports) {
2697
+ int err;
2698
+
2699
+ #define V(name, fn) \
2700
+ { \
2701
+ js_value_t *val; \
2702
+ err = js_create_function(env, name, -1, fn, NULL, &val); \
2703
+ assert(err == 0); \
2704
+ err = js_set_named_property(env, exports, name, val); \
2705
+ assert(err == 0); \
2706
+ }
2707
+
2708
+ V("requestInit", bare_fs_request_init)
2709
+ V("requestDestroy", bare_fs_request_destroy)
2710
+ V("requestReset", bare_fs_request_reset)
2711
+ V("requestResultStat", bare_fs_request_result_stat)
2712
+ V("requestResultStatfs", bare_fs_request_result_statfs)
2713
+ V("requestResultString", bare_fs_request_result_string)
2714
+ V("requestResultPath", bare_fs_request_result_path)
2715
+ V("requestResultDir", bare_fs_request_result_dir)
2716
+ V("requestResultDirents", bare_fs_request_result_dirents)
2717
+
2718
+ V("open", bare_fs_open)
2719
+ V("openSync", bare_fs_open_sync)
2720
+ V("close", bare_fs_close)
2721
+ V("closeSync", bare_fs_close_sync)
2722
+ V("access", bare_fs_access)
2723
+ V("accessSync", bare_fs_access_sync)
2724
+ V("read", bare_fs_read)
2725
+ V("readSync", bare_fs_read_sync)
2726
+ V("readv", bare_fs_readv)
2727
+ V("readvSync", bare_fs_readv_sync)
2728
+ V("write", bare_fs_write)
2729
+ V("writeSync", bare_fs_write_sync)
2730
+ V("writev", bare_fs_writev)
2731
+ V("writevSync", bare_fs_writev_sync)
2732
+ V("ftruncate", bare_fs_ftruncate)
2733
+ V("ftruncateSync", bare_fs_ftruncate_sync)
2734
+ V("chmod", bare_fs_chmod)
2735
+ V("chmodSync", bare_fs_chmod_sync)
2736
+ V("fchmod", bare_fs_fchmod)
2737
+ V("fchmodSync", bare_fs_fchmod_sync)
2738
+ V("chown", bare_fs_chown)
2739
+ V("chownSync", bare_fs_chown_sync)
2740
+ V("lchown", bare_fs_lchown)
2741
+ V("lchownSync", bare_fs_lchown_sync)
2742
+ V("fchown", bare_fs_fchown)
2743
+ V("fchownSync", bare_fs_fchown_sync)
2744
+ V("utimes", bare_fs_utimes)
2745
+ V("utimesSync", bare_fs_utimes_sync)
2746
+ V("lutimes", bare_fs_lutimes)
2747
+ V("lutimesSync", bare_fs_lutimes_sync)
2748
+ V("futimes", bare_fs_futimes)
2749
+ V("futimesSync", bare_fs_futimes_sync)
2750
+ V("rename", bare_fs_rename)
2751
+ V("renameSync", bare_fs_rename_sync)
2752
+ V("copyfile", bare_fs_copyfile)
2753
+ V("copyfileSync", bare_fs_copyfile_sync)
2754
+ V("mkdir", bare_fs_mkdir)
2755
+ V("mkdirSync", bare_fs_mkdir_sync)
2756
+ V("mkdtemp", bare_fs_mkdtemp)
2757
+ V("mkdtempSync", bare_fs_mkdtemp_sync)
2758
+ V("rmdir", bare_fs_rmdir)
2759
+ V("rmdirSync", bare_fs_rmdir_sync)
2760
+ V("stat", bare_fs_stat)
2761
+ V("statSync", bare_fs_stat_sync)
2762
+ V("lstat", bare_fs_lstat)
2763
+ V("lstatSync", bare_fs_lstat_sync)
2764
+ V("fstat", bare_fs_fstat)
2765
+ V("fstatSync", bare_fs_fstat_sync)
2766
+ V("statfs", bare_fs_statfs)
2767
+ V("statfsSync", bare_fs_statfs_sync)
2768
+ V("link", bare_fs_link)
2769
+ V("linkSync", bare_fs_link_sync)
2770
+ V("unlink", bare_fs_unlink)
2771
+ V("unlinkSync", bare_fs_unlink_sync)
2772
+ V("realpath", bare_fs_realpath)
2773
+ V("realpathSync", bare_fs_realpath_sync)
2774
+ V("readlink", bare_fs_readlink)
2775
+ V("readlinkSync", bare_fs_readlink_sync)
2776
+ V("symlink", bare_fs_symlink)
2777
+ V("symlinkSync", bare_fs_symlink_sync)
2778
+ V("opendir", bare_fs_opendir)
2779
+ V("opendirSync", bare_fs_opendir_sync)
2780
+ V("readdir", bare_fs_readdir)
2781
+ V("readdirSync", bare_fs_readdir_sync)
2782
+ V("closedir", bare_fs_closedir)
2783
+ V("closedirSync", bare_fs_closedir_sync)
2784
+ V("fsync", bare_fs_fsync)
2785
+ V("fsyncSync", bare_fs_fsync_sync)
2786
+ V("fdatasync", bare_fs_fdatasync)
2787
+ V("fdatasyncSync", bare_fs_fdatasync_sync)
2788
+
2789
+ V("watcherInit", bare_fs_watcher_init)
2790
+ V("watcherClose", bare_fs_watcher_close)
2791
+ V("watcherRef", bare_fs_watcher_ref)
2792
+ V("watcherUnref", bare_fs_watcher_unref)
2793
+ #undef V
2794
+
2795
+ #define V(name) \
2796
+ { \
2797
+ js_value_t *val; \
2798
+ err = js_create_uint32(env, name, &val); \
2799
+ assert(err == 0); \
2800
+ err = js_set_named_property(env, exports, #name, val); \
2801
+ assert(err == 0); \
2802
+ }
2803
+
2804
+ V(O_RDWR)
2805
+ V(O_RDONLY)
2806
+ V(O_WRONLY)
2807
+ V(O_CREAT)
2808
+ V(O_TRUNC)
2809
+ V(O_APPEND)
2810
+
2811
+ #ifdef F_OK
2812
+ V(F_OK)
2813
+ #endif
2814
+ #ifdef R_OK
2815
+ V(R_OK)
2816
+ #endif
2817
+ #ifdef W_OK
2818
+ V(W_OK)
2819
+ #endif
2820
+ #ifdef X_OK
2821
+ V(X_OK)
2822
+ #endif
2823
+
2824
+ V(S_IFMT)
2825
+ V(S_IFREG)
2826
+ V(S_IFDIR)
2827
+ V(S_IFCHR)
2828
+ V(S_IFLNK)
2829
+ #ifdef S_IFBLK
2830
+ V(S_IFBLK)
2831
+ #endif
2832
+ #ifdef S_IFIFO
2833
+ V(S_IFIFO)
2834
+ #endif
2835
+ #ifdef S_IFSOCK
2836
+ V(S_IFSOCK)
2837
+ #endif
2838
+
2839
+ #ifdef S_IRUSR
2840
+ V(S_IRUSR)
2841
+ #endif
2842
+ #ifdef S_IWUSR
2843
+ V(S_IWUSR)
2844
+ #endif
2845
+ #ifdef S_IXUSR
2846
+ V(S_IXUSR)
2847
+ #endif
2848
+ #ifdef S_IRGRP
2849
+ V(S_IRGRP)
2850
+ #endif
2851
+ #ifdef S_IWGRP
2852
+ V(S_IWGRP)
2853
+ #endif
2854
+ #ifdef S_IXGRP
2855
+ V(S_IXGRP)
2856
+ #endif
2857
+ #ifdef S_IROTH
2858
+ V(S_IROTH)
2859
+ #endif
2860
+ #ifdef S_IWOTH
2861
+ V(S_IWOTH)
2862
+ #endif
2863
+ #ifdef S_IXOTH
2864
+ V(S_IXOTH)
2865
+ #endif
2866
+
2867
+ V(UV_DIRENT_UNKNOWN)
2868
+ V(UV_DIRENT_FILE)
2869
+ V(UV_DIRENT_DIR)
2870
+ V(UV_DIRENT_LINK)
2871
+ V(UV_DIRENT_FIFO)
2872
+ V(UV_DIRENT_SOCKET)
2873
+ V(UV_DIRENT_CHAR)
2874
+ V(UV_DIRENT_BLOCK)
2875
+
2876
+ V(UV_FS_COPYFILE_EXCL)
2877
+ V(UV_FS_COPYFILE_FICLONE)
2878
+ V(UV_FS_COPYFILE_FICLONE_FORCE)
2879
+ V(UV_FS_SYMLINK_DIR)
2880
+ V(UV_FS_SYMLINK_JUNCTION)
2881
+
2882
+ V(UV_RENAME)
2883
+ V(UV_CHANGE)
2884
+ #undef V
2885
+
2886
+ return exports;
2887
+ }
2888
+
2889
+ BARE_MODULE(bare_fs, bare_fs_exports)
node_modules/bare-fs/binding.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = require.addon()
node_modules/bare-fs/index.d.ts ADDED
@@ -0,0 +1,1232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import EventEmitter, { EventMap } from 'bare-events'
2
+ import Buffer, { BufferEncoding } from 'bare-buffer'
3
+ import URL from 'bare-url'
4
+ import { Readable, Writable } from 'bare-stream'
5
+ import promises from './promises'
6
+ import constants from './lib/constants'
7
+
8
+ export { promises, constants }
9
+
10
+ export type Path = string | Buffer | URL
11
+
12
+ export type Flag =
13
+ | 'a'
14
+ | 'a+'
15
+ | 'as'
16
+ | 'as+'
17
+ | 'ax'
18
+ | 'ax+'
19
+ | 'r'
20
+ | 'r+'
21
+ | 'rs'
22
+ | 'rs+'
23
+ | 'sa'
24
+ | 'sa+'
25
+ | 'sr'
26
+ | 'sr+'
27
+ | 'w'
28
+ | 'w+'
29
+ | 'wx'
30
+ | 'wx+'
31
+ | 'xa'
32
+ | 'xa+'
33
+ | 'xw'
34
+ | 'xw+'
35
+
36
+ interface Callback<A extends unknown[] = []> {
37
+ (err: Error | null, ...args: A): void
38
+ }
39
+
40
+ export interface Dir<T extends string | Buffer = string | Buffer>
41
+ extends Iterable<Dirent>, AsyncIterable<Dirent> {
42
+ readonly path: string
43
+
44
+ read(): Promise<Dirent<T> | null>
45
+ read(cb: Callback<[dirent: Dirent<T> | null]>): void
46
+ readSync(): Dirent<T> | null
47
+
48
+ close(): Promise<void>
49
+ close(cb: Callback): void
50
+ closeSync(): void
51
+ }
52
+
53
+ export class Dir {
54
+ private constructor(path: string, handle: ArrayBuffer, opts?: OpendirOptions)
55
+ }
56
+
57
+ export interface Dirent<T extends string | Buffer = string | Buffer> {
58
+ readonly parentPath: string
59
+ readonly name: T
60
+ readonly type: number
61
+
62
+ isFile(): boolean
63
+ isDirectory(): boolean
64
+ isSymbolicLink(): boolean
65
+ isFIFO(): boolean
66
+ isSocket(): boolean
67
+ isCharacterDevice(): boolean
68
+ isBlockDevice(): boolean
69
+ }
70
+
71
+ export class Dirent<T extends string | Buffer = string | Buffer> {
72
+ private constructor(parentPath: string, name: T, type: number)
73
+ }
74
+
75
+ export interface Stats {
76
+ readonly dev: number
77
+ readonly mode: number
78
+ readonly nlink: number
79
+ readonly uid: number
80
+ readonly gid: number
81
+ readonly rdev: number
82
+ readonly blksize: number
83
+ readonly ino: number
84
+ readonly size: number
85
+ readonly blocks: number
86
+ readonly atimeMs: number
87
+ readonly mtimeMs: number
88
+ readonly ctimeMs: number
89
+ readonly birthtimeMs: number
90
+ readonly atime: Date
91
+ readonly mtime: Date
92
+ readonly ctime: Date
93
+ readonly birthtime: Date
94
+
95
+ isDirectory(): boolean
96
+ isFile(): boolean
97
+ isBlockDevice(): boolean
98
+ isCharacterDevice(): boolean
99
+ isFIFO(): boolean
100
+ isSymbolicLink(): boolean
101
+ isSocket(): boolean
102
+ }
103
+
104
+ export class Stats {
105
+ private constructor(
106
+ dev: number,
107
+ mode: number,
108
+ nlink: number,
109
+ uid: number,
110
+ gid: number,
111
+ rdev: number,
112
+ blksize: number,
113
+ ino: number,
114
+ size: number,
115
+ blocks: number,
116
+ atimeMs: number,
117
+ mtimeMs: number,
118
+ ctimeMs: number,
119
+ birthtimeMs: number
120
+ )
121
+ }
122
+
123
+ export interface StatFs {
124
+ readonly type: number
125
+ readonly bsize: number
126
+ readonly blocks: number
127
+ readonly bfree: number
128
+ readonly bavail: number
129
+ readonly files: number
130
+ readonly ffree: number
131
+ }
132
+
133
+ export class StatFs {
134
+ private constructor(
135
+ type: number,
136
+ bsize: number,
137
+ blocks: number,
138
+ bfree: number,
139
+ bavail: number,
140
+ files: number,
141
+ ffree: number
142
+ )
143
+ }
144
+
145
+ export interface ReadStreamOptions {
146
+ fd?: number
147
+ flags?: Flag
148
+ mode?: number
149
+ start?: number
150
+ end?: number
151
+ }
152
+
153
+ export interface ReadStream extends Readable {
154
+ readonly path: string | null
155
+ readonly fd: number
156
+ readonly flags: Flag
157
+ readonly mode: number
158
+ }
159
+
160
+ export class ReadStream {
161
+ private constructor(path: Path | null, opts?: ReadStreamOptions)
162
+ }
163
+
164
+ export function createReadStream(path: Path | null, opts?: ReadStreamOptions): ReadStream
165
+
166
+ export interface WriteStreamOptions {
167
+ fd?: number
168
+ flags?: Flag
169
+ mode?: number
170
+ }
171
+
172
+ export interface WriteStream extends Writable {
173
+ readonly path: string | null
174
+ readonly fd: number
175
+ readonly flags: Flag
176
+ readonly mode: number
177
+ }
178
+
179
+ export class WriteStream {
180
+ private constructor(path: Path | null, opts?: WriteStreamOptions)
181
+ }
182
+
183
+ export function createWriteStream(path: Path | null, opts?: WriteStreamOptions): WriteStream
184
+
185
+ export interface WatcherOptions {
186
+ persistent?: boolean
187
+ recursive?: boolean
188
+ encoding?: BufferEncoding | 'buffer'
189
+ }
190
+
191
+ export type WatcherEventType = 'rename' | 'change'
192
+
193
+ export interface WatcherEvents<T extends string | Buffer = string | Buffer> extends EventMap {
194
+ error: [err: Error]
195
+ change: [eventType: WatcherEventType, filename: T]
196
+ close: []
197
+ }
198
+
199
+ export interface Watcher<T extends string | Buffer = string | Buffer>
200
+ extends
201
+ EventEmitter<WatcherEvents<T>>,
202
+ AsyncIterable<{ eventType: WatcherEventType; filename: T }> {
203
+ close(): void
204
+ ref(): void
205
+ unref(): void
206
+ }
207
+
208
+ export class Watcher {
209
+ private constructor(path: Path, opts: WatcherOptions)
210
+ }
211
+
212
+ export function access(filepath: Path, mode?: number): Promise<void>
213
+
214
+ export function access(filepath: Path, mode: number, cb: Callback): void
215
+
216
+ export function access(filepath: Path, cb: Callback): void
217
+
218
+ export function accessSync(filepath: Path, mode?: number): void
219
+
220
+ export interface AppendFileOptions {
221
+ encoding?: BufferEncoding
222
+ flag?: string
223
+ mode?: number
224
+ }
225
+
226
+ export function appendFile(
227
+ filepath: Path,
228
+ data: string | Buffer | ArrayBufferView,
229
+ opts?: AppendFileOptions
230
+ ): Promise<void>
231
+
232
+ export function appendFile(
233
+ filepath: Path,
234
+ data: string | Buffer | ArrayBufferView,
235
+ encoding: BufferEncoding
236
+ ): Promise<void>
237
+
238
+ export function appendFile(
239
+ filepath: Path,
240
+ data: string | Buffer | ArrayBufferView,
241
+ opts: AppendFileOptions,
242
+ cb: Callback
243
+ ): void
244
+
245
+ export function appendFile(
246
+ filepath: Path,
247
+ data: string | Buffer | ArrayBufferView,
248
+ encoding: BufferEncoding,
249
+ cb: Callback
250
+ ): void
251
+
252
+ export function appendFile(
253
+ filepath: Path,
254
+ data: string | Buffer | ArrayBufferView,
255
+ cb: Callback
256
+ ): void
257
+
258
+ export function appendFileSync(
259
+ filepath: Path,
260
+ data: string | Buffer | ArrayBufferView,
261
+ opts?: AppendFileOptions
262
+ ): void
263
+
264
+ export function appendFileSync(
265
+ filepath: Path,
266
+ data: string | Buffer | ArrayBufferView,
267
+ encoding: BufferEncoding
268
+ ): void
269
+
270
+ export function chmod(filepath: Path, mode: string | number): Promise<void>
271
+
272
+ export function chmod(filepath: Path, mode: string | number, cb: Callback): void
273
+
274
+ export function chmodSync(filepath: Path, mode: string | number): void
275
+
276
+ export function chown(filepath: Path, uid: number, gid: number): Promise<void>
277
+
278
+ export function chown(filepath: Path, uid: number, gid: number, cb: Callback): void
279
+
280
+ export function chownSync(filepath: Path, uid: number, gid: number): void
281
+
282
+ export function close(fd: number): Promise<void>
283
+
284
+ export function close(fd: number, cb: Callback): void
285
+
286
+ export function closeSync(fd: number): void
287
+
288
+ export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
289
+
290
+ export function copyFile(src: Path, dst: Path, mode: number, cb: Callback): void
291
+
292
+ export function copyFile(src: Path, dst: Path, cb: Callback): void
293
+
294
+ export function copyFileSync(src: Path, dst: Path, mode?: number): void
295
+
296
+ export interface CpOptions {
297
+ recursive?: boolean
298
+ }
299
+
300
+ export function cp(src: Path, dst: Path, opts?: CpOptions): Promise<void>
301
+
302
+ export function cp(src: Path, dst: Path, opts: CpOptions, cb: Callback): void
303
+
304
+ export function cp(src: Path, dst: Path, cb: Callback): void
305
+
306
+ export function cpSync(src: Path, dst: Path, opts?: CpOptions): void
307
+
308
+ export function exists(filepath: Path): Promise<boolean>
309
+
310
+ export function exists(filepath: Path, cb: (exists: boolean) => void): void
311
+
312
+ export function existsSync(filepath: Path): boolean
313
+
314
+ export function fchmod(fd: number, mode: string | number): Promise<void>
315
+
316
+ export function fchmod(fd: number, mode: string | number, cb: Callback): void
317
+
318
+ export function fchmodSync(fd: number, mode: string | number): void
319
+
320
+ export function fchown(fd: number, uid: number, gid: number): Promise<void>
321
+
322
+ export function fchown(fd: number, uid: number, gid: number, cb: Callback): void
323
+
324
+ export function fchownSync(fd: number, uid: number, gid: number): void
325
+
326
+ export function fdatasync(fd: number): Promise<void>
327
+
328
+ export function fdatasync(fd: number, cb: Callback): void
329
+
330
+ export function fdatasyncSync(fd: number): void
331
+
332
+ export function fstat(fd: number): Promise<Stats>
333
+
334
+ export function fstat(fd: number, cb: Callback<[stats: Stats | null]>): void
335
+
336
+ export function fstatSync(fd: number): Stats
337
+
338
+ export function fsync(fd: number): Promise<void>
339
+
340
+ export function fsync(fd: number, cb: Callback): void
341
+
342
+ export function fsyncSync(fd: number): void
343
+
344
+ export function ftruncate(fd: number, len?: number): Promise<void>
345
+
346
+ export function ftruncate(fd: number, len: number, cb: Callback): void
347
+
348
+ export function ftruncate(fd: number, cb: Callback): void
349
+
350
+ export function ftruncateSync(fd: number, len?: number): void
351
+
352
+ export function lchown(filepath: Path, uid: number, gid: number): Promise<void>
353
+
354
+ export function lchown(filepath: Path, uid: number, gid: number, cb: Callback): void
355
+
356
+ export function lchownSync(filepath: Path, uid: number, gid: number): void
357
+
358
+ export function lstat(filepath: Path): Promise<Stats>
359
+
360
+ export function lstat(filepath: Path, cb: Callback<[stats: Stats | null]>): void
361
+
362
+ export function lstatSync(filepath: Path): Stats
363
+
364
+ export function utimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
365
+
366
+ export function utimes(
367
+ filepath: Path,
368
+ atime: number | Date,
369
+ mtime: number | Date,
370
+ cb: Callback
371
+ ): void
372
+
373
+ export function utimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
374
+
375
+ export function lutimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
376
+
377
+ export function lutimes(
378
+ filepath: Path,
379
+ atime: number | Date,
380
+ mtime: number | Date,
381
+ cb: Callback
382
+ ): void
383
+
384
+ export function lutimesSync(filepath: Path, atime: number | Date, mtime: number | Date): void
385
+
386
+ export function futimes(fd: number, atime: number | Date, mtime: number | Date): Promise<void>
387
+
388
+ export function futimes(fd: number, atime: number | Date, mtime: number | Date, cb: Callback): void
389
+
390
+ export function futimesSync(fd: number, atime: number | Date, mtime: number | Date): void
391
+
392
+ export function link(src: Path, dst: Path): Promise<void>
393
+
394
+ export function link(src: Path, dst: Path, cb: Callback): void
395
+
396
+ export function linkSync(src: Path, dst: Path): void
397
+
398
+ export interface MkdirOptions {
399
+ mode?: number
400
+ recursive?: boolean
401
+ }
402
+
403
+ export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
404
+
405
+ export function mkdir(filepath: Path, mode: number): Promise<void>
406
+
407
+ export function mkdir(filepath: Path, opts: MkdirOptions, cb: Callback): void
408
+
409
+ export function mkdir(filepath: Path, mode: number, cb: Callback): void
410
+
411
+ export function mkdir(filepath: Path, cb: Callback): void
412
+
413
+ export function mkdirSync(filepath: Path, opts?: MkdirOptions): void
414
+
415
+ export function mkdirSync(filepath: Path, mode: number): void
416
+
417
+ export function mkdtemp(prefix: Path): Promise<string>
418
+
419
+ export function mkdtemp(prefix: Path, cb: Callback<[path: string | null]>): void
420
+
421
+ export function mkdtempSync(prefix: Path): string
422
+
423
+ export function open(filepath: Path, flags?: Flag | number, mode?: string | number): Promise<number>
424
+
425
+ export function open(
426
+ filepath: Path,
427
+ flags: Flag | number,
428
+ mode: string | number,
429
+ cb: Callback<[fd: number]>
430
+ ): void
431
+
432
+ export function open(filepath: Path, flags: Flag | number, cb: Callback<[fd: number]>): void
433
+
434
+ export function open(filepath: Path, cb: Callback<[fd: number]>): void
435
+
436
+ export function openSync(filepath: Path, flags?: Flag | number, mode?: string | number): number
437
+
438
+ export interface OpendirOptions {
439
+ encoding?: BufferEncoding | 'buffer'
440
+ bufferSize?: number
441
+ }
442
+
443
+ export function opendir(
444
+ filepath: Path,
445
+ opts: OpendirOptions & { encoding?: BufferEncoding }
446
+ ): Promise<Dir<string>>
447
+
448
+ export function opendir(
449
+ filepath: Path,
450
+ opts: OpendirOptions & { encoding: 'buffer' }
451
+ ): Promise<Dir<Buffer>>
452
+
453
+ export function opendir(filepath: Path, opts: OpendirOptions): Promise<Dir>
454
+
455
+ export function opendir(filepath: Path, encoding: BufferEncoding): Promise<Dir<string>>
456
+
457
+ export function opendir(filepath: Path, encoding: 'buffer'): Promise<Dir<Buffer>>
458
+
459
+ export function opendir(filepath: Path, encoding: BufferEncoding | 'buffer'): Promise<Dir>
460
+
461
+ export function opendir(filepath: Path): Promise<Dir<string>>
462
+
463
+ export function opendir(
464
+ filepath: Path,
465
+ opts: OpendirOptions & { encoding?: BufferEncoding },
466
+ cb: Callback<[dir: Dir<string> | null]>
467
+ ): void
468
+
469
+ export function opendir(
470
+ filepath: Path,
471
+ opts: OpendirOptions & { encoding: 'buffer' },
472
+ cb: Callback<[dir: Dir<Buffer> | null]>
473
+ ): void
474
+
475
+ export function opendir(filepath: Path, opts: OpendirOptions, cb: Callback<[dir: Dir | null]>): void
476
+
477
+ export function opendir(
478
+ filepath: Path,
479
+ encoding: BufferEncoding,
480
+ cb: Callback<[dir: Dir<string> | null]>
481
+ ): void
482
+
483
+ export function opendir(
484
+ filepath: Path,
485
+ encoding: 'buffer',
486
+ cb: Callback<[dir: Dir<Buffer> | null]>
487
+ ): void
488
+
489
+ export function opendir(
490
+ filepath: Path,
491
+ encoding: BufferEncoding | 'buffer',
492
+ cb: Callback<[dir: Dir | null]>
493
+ ): void
494
+
495
+ export function opendir(filepath: Path, cb: Callback<[dir: Dir<string> | null]>): void
496
+
497
+ export function opendirSync(
498
+ filepath: Path,
499
+ opts: OpendirOptions & { encoding?: BufferEncoding }
500
+ ): Dir<string>
501
+
502
+ export function opendirSync(
503
+ filepath: Path,
504
+ opts: OpendirOptions & { encoding: 'buffer' }
505
+ ): Dir<Buffer>
506
+
507
+ export function opendirSync(filepath: Path, opts: OpendirOptions): Dir
508
+
509
+ export function opendirSync(filepath: Path, encoding: BufferEncoding): Dir<string>
510
+
511
+ export function opendirSync(filepath: Path, encoding: 'buffer'): Dir<Buffer>
512
+
513
+ export function opendirSync(filepath: Path, encoding: BufferEncoding | 'buffer'): Dir
514
+
515
+ export function opendirSync(filepath: Path): Dir<string>
516
+
517
+ export function read(
518
+ fd: number,
519
+ buffer: Buffer | ArrayBufferView,
520
+ offset?: number,
521
+ len?: number,
522
+ pos?: number
523
+ ): Promise<number>
524
+
525
+ export function read(
526
+ fd: number,
527
+ buffer: Buffer | ArrayBufferView,
528
+ offset: number,
529
+ len: number,
530
+ pos: number,
531
+ cb: Callback<[len: number]>
532
+ ): void
533
+
534
+ export function read(
535
+ fd: number,
536
+ buffer: Buffer | ArrayBufferView,
537
+ offset: number,
538
+ len: number,
539
+ cb: Callback<[len: number]>
540
+ ): void
541
+
542
+ export function read(
543
+ fd: number,
544
+ buffer: Buffer | ArrayBufferView,
545
+ offset: number,
546
+ cb: Callback<[len: number]>
547
+ ): void
548
+
549
+ export function read(
550
+ fd: number,
551
+ buffer: Buffer | ArrayBufferView,
552
+ cb: Callback<[len: number]>
553
+ ): void
554
+
555
+ export function readSync(
556
+ fd: number,
557
+ buffer: Buffer | ArrayBufferView,
558
+ offset?: number,
559
+ len?: number,
560
+ pos?: number
561
+ ): number
562
+
563
+ export interface ReadFileOptions {
564
+ encoding?: BufferEncoding | 'buffer'
565
+ flag?: Flag
566
+ }
567
+
568
+ export function readFile(
569
+ filepath: Path,
570
+ opts: ReadFileOptions & { encoding: BufferEncoding }
571
+ ): Promise<string>
572
+
573
+ export function readFile(
574
+ filepath: Path,
575
+ opts: ReadFileOptions & { encoding?: 'buffer' }
576
+ ): Promise<Buffer>
577
+
578
+ export function readFile(filepath: Path, opts: ReadFileOptions): Promise<string | Buffer>
579
+
580
+ export function readFile(filepath: Path, encoding: BufferEncoding): Promise<string>
581
+
582
+ export function readFile(filepath: Path, encoding: 'buffer'): Promise<Buffer>
583
+
584
+ export function readFile(
585
+ filepath: Path,
586
+ encoding?: BufferEncoding | 'buffer'
587
+ ): Promise<string | Buffer>
588
+
589
+ export function readFile(filepath: Path): Promise<Buffer>
590
+
591
+ export function readFile(
592
+ filepath: Path,
593
+ opts: ReadFileOptions & { encoding: BufferEncoding },
594
+ cb: Callback<[buffer?: string]>
595
+ ): void
596
+
597
+ export function readFile(
598
+ filepath: Path,
599
+ opts: ReadFileOptions & { encoding?: 'buffer' },
600
+ cb: Callback<[buffer?: Buffer]>
601
+ ): void
602
+
603
+ export function readFile(
604
+ filepath: Path,
605
+ opts: ReadFileOptions,
606
+ cb: Callback<[buffer?: string | Buffer]>
607
+ ): void
608
+
609
+ export function readFile(
610
+ filepath: Path,
611
+ encoding: BufferEncoding,
612
+ cb: Callback<[buffer?: string]>
613
+ ): void
614
+
615
+ export function readFile(filepath: Path, encoding: 'buffer', cb: Callback<[buffer?: Buffer]>): void
616
+
617
+ export function readFile(
618
+ filepath: Path,
619
+ encoding: BufferEncoding | 'buffer',
620
+ cb: Callback<[buffer?: string | Buffer]>
621
+ ): void
622
+
623
+ export function readFile(filepath: Path, cb: Callback<[buffer?: Buffer]>): void
624
+
625
+ export function readFileSync(
626
+ filepath: Path,
627
+ opts: ReadFileOptions & { encoding: BufferEncoding }
628
+ ): string
629
+
630
+ export function readFileSync(
631
+ filepath: Path,
632
+ opts: ReadFileOptions & { encoding?: 'buffer' }
633
+ ): Buffer
634
+
635
+ export function readFileSync(filepath: Path, opts: ReadFileOptions): string | Buffer
636
+
637
+ export function readFileSync(filepath: Path, encoding: BufferEncoding): string
638
+
639
+ export function readFileSync(filepath: Path, encoding: 'buffer'): Buffer
640
+
641
+ export function readFileSync(filepath: Path, encoding?: BufferEncoding | 'buffer'): string | Buffer
642
+
643
+ export function readFileSync(filepath: Path): Buffer
644
+
645
+ export interface ReaddirOptions extends OpendirOptions {
646
+ withFileTypes?: boolean
647
+ }
648
+ export function readdir(
649
+ filepath: Path,
650
+ opts: ReaddirOptions & { encoding?: BufferEncoding }
651
+ ): Promise<Dirent<string>[] | string[]>
652
+
653
+ export function readdir(
654
+ filepath: Path,
655
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
656
+ ): Promise<Dirent<string>[]>
657
+
658
+ export function readdir(
659
+ filepath: Path,
660
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes?: false }
661
+ ): Promise<string[]>
662
+
663
+ export function readdir(
664
+ filepath: Path,
665
+ opts: ReaddirOptions & { encoding: 'buffer' }
666
+ ): Promise<Dirent<Buffer>[] | Buffer[]>
667
+
668
+ export function readdir(
669
+ filepath: Path,
670
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
671
+ ): Promise<Dirent<Buffer>[]>
672
+
673
+ export function readdir(
674
+ filepath: Path,
675
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes?: false }
676
+ ): Promise<Buffer[]>
677
+
678
+ export function readdir(
679
+ filepath: Path,
680
+ opts: ReaddirOptions & { withFileTypes: true }
681
+ ): Promise<Dirent<string | Buffer>[]>
682
+
683
+ export function readdir(
684
+ filepath: Path,
685
+ opts: ReaddirOptions & { withFileTypes?: false }
686
+ ): Promise<string[] | Buffer[]>
687
+
688
+ export function readdir(
689
+ filepath: Path,
690
+ opts: ReaddirOptions
691
+ ): Promise<Dirent[] | string[] | Buffer[]>
692
+
693
+ export function readdir(filepath: Path, encoding: BufferEncoding): Promise<string[]>
694
+
695
+ export function readdir(filepath: Path, encoding: 'buffer'): Promise<Buffer[]>
696
+
697
+ export function readdir(
698
+ filepath: Path,
699
+ encoding: BufferEncoding | 'buffer'
700
+ ): Promise<string[] | Buffer[]>
701
+
702
+ export function readdir(filepath: Path): Promise<string[]>
703
+
704
+ export function readdir(
705
+ filepath: Path,
706
+ opts: ReaddirOptions & { encoding?: BufferEncoding },
707
+ cb: Callback<[entries: Dirent<string>[] | string[] | null]>
708
+ ): void
709
+
710
+ export function readdir(
711
+ filepath: Path,
712
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true },
713
+ cb: Callback<[entries: Dirent<string>[] | null]>
714
+ ): void
715
+
716
+ export function readdir(
717
+ filepath: Path,
718
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes?: false },
719
+ cb: Callback<[entries: string[] | null]>
720
+ ): void
721
+
722
+ export function readdir(
723
+ filepath: Path,
724
+ opts: ReaddirOptions & { encoding: 'buffer' },
725
+ cb: Callback<[entries: Dirent<Buffer>[] | Buffer[] | null]>
726
+ ): void
727
+
728
+ export function readdir(
729
+ filepath: Path,
730
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true },
731
+ cb: Callback<[entries: Dirent<Buffer>[] | null]>
732
+ ): void
733
+
734
+ export function readdir(
735
+ filepath: Path,
736
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes?: false },
737
+ cb: Callback<[entries: Buffer[] | null]>
738
+ ): void
739
+
740
+ export function readdir(
741
+ filepath: Path,
742
+ opts: ReaddirOptions & { withFileTypes: true },
743
+ cb: Callback<[entries: Dirent<string | Buffer>[] | null]>
744
+ ): void
745
+
746
+ export function readdir(
747
+ filepath: Path,
748
+ opts: ReaddirOptions & { withFileTypes?: false },
749
+ cb: Callback<[entries: string[] | Buffer[] | null]>
750
+ ): void
751
+
752
+ export function readdir(
753
+ filepath: Path,
754
+ opts: ReaddirOptions,
755
+ cb: Callback<[entries: Dirent[] | string[] | Buffer[] | null]>
756
+ ): void
757
+
758
+ export function readdir(
759
+ filepath: Path,
760
+ encoding: BufferEncoding,
761
+ cb: Callback<[entries: string[] | null]>
762
+ ): void
763
+
764
+ export function readdir(
765
+ filepath: Path,
766
+ encoding: 'buffer',
767
+ cb: Callback<[entries: Buffer[] | null]>
768
+ ): void
769
+
770
+ export function readdir(
771
+ filepath: Path,
772
+ encoding: BufferEncoding | 'buffer',
773
+ cb: Callback<[entries: string[] | Buffer[] | null]>
774
+ ): void
775
+
776
+ export function readdir(filepath: Path, cb: Callback<[entries: string[] | null]>): void
777
+
778
+ export function readdirSync(
779
+ filepath: Path,
780
+ opts: ReaddirOptions & { encoding?: BufferEncoding }
781
+ ): Dirent<string>[] | string[]
782
+
783
+ export function readdirSync(
784
+ filepath: Path,
785
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
786
+ ): Dirent<string>[]
787
+
788
+ export function readdirSync(
789
+ filepath: Path,
790
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes?: false }
791
+ ): string[]
792
+
793
+ export function readdirSync(
794
+ filepath: Path,
795
+ opts: ReaddirOptions & { encoding: 'buffer' }
796
+ ): Dirent<Buffer>[] | Buffer[]
797
+
798
+ export function readdirSync(
799
+ filepath: Path,
800
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
801
+ ): Dirent<Buffer>[]
802
+
803
+ export function readdirSync(
804
+ filepath: Path,
805
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes?: false }
806
+ ): Buffer[]
807
+
808
+ export function readdirSync(
809
+ filepath: Path,
810
+ opts: ReaddirOptions & { withFileTypes: true }
811
+ ): Dirent<string | Buffer>[]
812
+
813
+ export function readdirSync(
814
+ filepath: Path,
815
+ opts: ReaddirOptions & { withFileTypes?: false }
816
+ ): string[] | Buffer[]
817
+
818
+ export function readdirSync(filepath: Path, opts: ReaddirOptions): Dirent[] | string[] | Buffer[]
819
+
820
+ export function readdirSync(filepath: Path, encoding: BufferEncoding): string[]
821
+
822
+ export function readdirSync(filepath: Path, encoding: 'buffer'): Buffer[]
823
+
824
+ export function readdirSync(
825
+ filepath: Path,
826
+ encoding: BufferEncoding | 'buffer'
827
+ ): string[] | Buffer[]
828
+
829
+ export function readdirSync(filepath: Path): string[]
830
+
831
+ export interface ReadlinkOptions {
832
+ encoding?: BufferEncoding | 'buffer'
833
+ }
834
+
835
+ export function readlink(
836
+ filepath: Path,
837
+ opts: ReadlinkOptions & { encoding?: BufferEncoding }
838
+ ): Promise<string>
839
+
840
+ export function readlink(
841
+ filepath: Path,
842
+ opts: ReadlinkOptions & { encoding: 'buffer' }
843
+ ): Promise<Buffer>
844
+
845
+ export function readlink(filepath: Path, opts: ReadlinkOptions): Promise<string | Buffer>
846
+
847
+ export function readlink(filepath: Path, encoding: BufferEncoding): Promise<string>
848
+
849
+ export function readlink(filepath: Path, encoding: 'buffer'): Promise<Buffer>
850
+
851
+ export function readlink(
852
+ filepath: Path,
853
+ encoding: BufferEncoding | 'buffer'
854
+ ): Promise<string | Buffer>
855
+
856
+ export function readlink(filepath: Path): Promise<string>
857
+
858
+ export function readlink(
859
+ filepath: Path,
860
+ opts: ReadlinkOptions & { encoding?: BufferEncoding },
861
+ cb: Callback<[link: string | null]>
862
+ ): void
863
+
864
+ export function readlink(
865
+ filepath: Path,
866
+ opts: ReadlinkOptions & { encoding: 'buffer' },
867
+ cb: Callback<[link: Buffer | null]>
868
+ ): void
869
+
870
+ export function readlink(
871
+ filepath: Path,
872
+ opts: ReadlinkOptions,
873
+ cb: Callback<[link: string | Buffer | null]>
874
+ ): void
875
+
876
+ export function readlink(
877
+ filepath: Path,
878
+ encoding: BufferEncoding,
879
+ cb: Callback<[link: string | null]>
880
+ ): void
881
+
882
+ export function readlink(
883
+ filepath: Path,
884
+ encoding: 'buffer',
885
+ cb: Callback<[link: Buffer | null]>
886
+ ): void
887
+
888
+ export function readlink(
889
+ filepath: Path,
890
+ encoding: BufferEncoding | 'buffer',
891
+ cb: Callback<[link: string | Buffer | null]>
892
+ ): void
893
+
894
+ export function readlink(filepath: Path, cb: Callback<[link: string | null]>): void
895
+
896
+ export function readlinkSync(
897
+ filepath: Path,
898
+ opts: ReadlinkOptions & { encoding?: BufferEncoding }
899
+ ): string
900
+
901
+ export function readlinkSync(filepath: Path, opts: ReadlinkOptions & { encoding: 'buffer' }): Buffer
902
+
903
+ export function readlinkSync(filepath: Path, opts: ReadlinkOptions): string | Buffer
904
+
905
+ export function readlinkSync(filepath: Path, encoding: BufferEncoding): string
906
+
907
+ export function readlinkSync(filepath: Path, encoding: 'buffer'): Buffer
908
+
909
+ export function readlinkSync(filepath: Path, encoding: BufferEncoding | 'buffer'): string | Buffer
910
+
911
+ export function readlinkSync(filepath: Path): string
912
+
913
+ export function readv(fd: number, buffers: ArrayBufferView[], position?: number): Promise<number>
914
+
915
+ export function readv(
916
+ fd: number,
917
+ buffers: ArrayBufferView[],
918
+ position: number,
919
+ cb: Callback<[len: number]>
920
+ ): void
921
+
922
+ export function readv(fd: number, buffers: ArrayBufferView[], cb: Callback<[len: number]>): void
923
+
924
+ export function readvSync(fd: number, buffers: ArrayBufferView[], position?: number): number
925
+
926
+ export interface RealpathOptions {
927
+ encoding?: BufferEncoding | 'buffer'
928
+ }
929
+
930
+ export function realpath(
931
+ filepath: Path,
932
+ opts: RealpathOptions & { encoding?: BufferEncoding }
933
+ ): Promise<string>
934
+
935
+ export function realpath(
936
+ filepath: Path,
937
+ opts: RealpathOptions & { encoding: 'buffer' }
938
+ ): Promise<Buffer>
939
+
940
+ export function realpath(filepath: Path, opts: RealpathOptions): Promise<string | Buffer>
941
+
942
+ export function realpath(filepath: Path, encoding: BufferEncoding): Promise<string>
943
+
944
+ export function realpath(filepath: Path, encoding: 'buffer'): Promise<Buffer>
945
+
946
+ export function realpath(
947
+ filepath: Path,
948
+ encoding: BufferEncoding | 'buffer'
949
+ ): Promise<string | Buffer>
950
+
951
+ export function realpath(filepath: Path): Promise<string>
952
+
953
+ export function realpath(
954
+ filepath: Path,
955
+ opts: RealpathOptions & { encoding?: BufferEncoding },
956
+ cb: Callback<[path: string | null]>
957
+ ): void
958
+
959
+ export function realpath(
960
+ filepath: Path,
961
+ opts: RealpathOptions & { encoding: 'buffer' },
962
+ cb: Callback<[path: Buffer | null]>
963
+ ): void
964
+
965
+ export function realpath(
966
+ filepath: Path,
967
+ opts: RealpathOptions,
968
+ cb: Callback<[path: string | Buffer | null]>
969
+ ): void
970
+
971
+ export function realpath(
972
+ filepath: Path,
973
+ encoding: BufferEncoding,
974
+ cb: Callback<[path: string | null]>
975
+ ): void
976
+
977
+ export function realpath(
978
+ filepath: Path,
979
+ encoding: 'buffer',
980
+ cb: Callback<[path: Buffer | null]>
981
+ ): void
982
+
983
+ export function realpath(
984
+ filepath: Path,
985
+ encoding: BufferEncoding | 'buffer',
986
+ cb: Callback<[path: string | Buffer | null]>
987
+ ): void
988
+
989
+ export function realpath(filepath: Path, cb: Callback<[path: string | null]>): void
990
+
991
+ export function realpathSync(
992
+ filepath: Path,
993
+ opts: RealpathOptions & { encoding?: BufferEncoding }
994
+ ): string
995
+
996
+ export function realpathSync(filepath: Path, opts: RealpathOptions & { encoding: 'buffer' }): Buffer
997
+
998
+ export function realpathSync(filepath: Path, opts: RealpathOptions): string | Buffer
999
+
1000
+ export function realpathSync(filepath: Path, encoding: BufferEncoding): string
1001
+
1002
+ export function realpathSync(filepath: Path, encoding: 'buffer'): Buffer
1003
+
1004
+ export function realpathSync(filepath: Path, encoding: BufferEncoding | 'buffer'): string | Buffer
1005
+
1006
+ export function realpathSync(filepath: Path): string
1007
+
1008
+ export function rename(src: Path, dst: Path): Promise<void>
1009
+
1010
+ export function rename(src: Path, dst: Path, cb: Callback): void
1011
+
1012
+ export function renameSync(src: Path, dst: Path): void
1013
+
1014
+ export interface RmOptions {
1015
+ force?: boolean
1016
+ recursive?: boolean
1017
+ }
1018
+
1019
+ export function rm(filepath: Path, opts?: RmOptions): Promise<void>
1020
+
1021
+ export function rm(filepath: Path, opts: RmOptions, cb: Callback): void
1022
+
1023
+ export function rm(filepath: Path, cb: Callback): void
1024
+
1025
+ export function rmSync(filepath: Path, opts?: RmOptions): void
1026
+
1027
+ export function rmdir(filepath: Path): Promise<void>
1028
+
1029
+ export function rmdir(filepath: Path, cb: Callback): void
1030
+
1031
+ export function rmdirSync(filepath: Path): void
1032
+
1033
+ export function stat(filepath: Path): Promise<Stats>
1034
+
1035
+ export function stat(filepath: Path, cb: Callback<[stats: Stats | null]>): void
1036
+
1037
+ export function statSync(filepath: Path): Stats
1038
+
1039
+ export function statfs(filepath: Path): Promise<StatFs>
1040
+
1041
+ export function statfs(filepath: Path, cb: Callback<[stats: StatFs | null]>): void
1042
+
1043
+ export function statfsSync(filepath: Path): StatFs
1044
+
1045
+ export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>
1046
+
1047
+ export function symlink(target: Path, filepath: Path, type: string | number, cb: Callback): void
1048
+
1049
+ export function symlink(target: Path, filepath: Path, cb: Callback): void
1050
+
1051
+ export function symlinkSync(target: Path, filepath: Path, type?: string | number): void
1052
+
1053
+ export function truncate(filepath: Path, len?: number): Promise<void>
1054
+
1055
+ export function truncate(filepath: Path, len: number, cb: Callback): void
1056
+
1057
+ export function truncate(filepath: Path, cb: Callback): void
1058
+
1059
+ export function truncateSync(filepath: Path, len?: number): void
1060
+
1061
+ export function unlink(filepath: Path): Promise<void>
1062
+
1063
+ export function unlink(filepath: Path, cb: Callback): void
1064
+
1065
+ export function unlinkSync(filepath: Path): void
1066
+
1067
+ export function watch(
1068
+ filepath: Path,
1069
+ opts: WatcherOptions & { encoding?: BufferEncoding },
1070
+ cb: (eventType: WatcherEventType, filename: string) => void
1071
+ ): Watcher<string>
1072
+
1073
+ export function watch(
1074
+ filepath: Path,
1075
+ opts: WatcherOptions & { encoding: 'buffer' },
1076
+ cb: (eventType: WatcherEventType, filename: Buffer) => void
1077
+ ): Watcher<Buffer>
1078
+
1079
+ export function watch(
1080
+ filepath: Path,
1081
+ opts: WatcherOptions,
1082
+ cb: (eventType: WatcherEventType, filename: string | Buffer) => void
1083
+ ): Watcher
1084
+
1085
+ export function watch(
1086
+ filepath: Path,
1087
+ encoding: BufferEncoding,
1088
+ cb: (eventType: WatcherEventType, filename: string) => void
1089
+ ): Watcher<string>
1090
+
1091
+ export function watch(
1092
+ filepath: Path,
1093
+ encoding: 'buffer',
1094
+ cb: (eventType: WatcherEventType, filename: Buffer) => void
1095
+ ): Watcher<Buffer>
1096
+
1097
+ export function watch(
1098
+ filepath: Path,
1099
+ encoding: BufferEncoding | 'buffer',
1100
+ cb: (eventType: WatcherEventType, filename: string | Buffer) => void
1101
+ ): Watcher
1102
+
1103
+ export function watch(
1104
+ filepath: Path,
1105
+ cb: (eventType: WatcherEventType, filename: string) => void
1106
+ ): Watcher<string>
1107
+
1108
+ export function write(
1109
+ fd: number,
1110
+ data: Buffer | ArrayBufferView,
1111
+ offset?: number,
1112
+ len?: number,
1113
+ pos?: number
1114
+ ): Promise<number>
1115
+
1116
+ export function write(
1117
+ fd: number,
1118
+ data: string,
1119
+ pos?: number,
1120
+ encoding?: BufferEncoding
1121
+ ): Promise<number>
1122
+
1123
+ export function write(
1124
+ fd: number,
1125
+ data: Buffer | ArrayBufferView,
1126
+ offset: number,
1127
+ len: number,
1128
+ pos: number,
1129
+ cb: Callback<[len: number]>
1130
+ ): void
1131
+
1132
+ export function write(
1133
+ fd: number,
1134
+ data: Buffer | ArrayBufferView,
1135
+ offset: number,
1136
+ len: number,
1137
+ cb: Callback<[len: number]>
1138
+ ): void
1139
+
1140
+ export function write(
1141
+ fd: number,
1142
+ data: string,
1143
+ pos: number,
1144
+ encoding: BufferEncoding,
1145
+ cb: Callback<[len: number]>
1146
+ ): void
1147
+
1148
+ export function write(
1149
+ fd: number,
1150
+ data: Buffer | ArrayBufferView,
1151
+ offset: number,
1152
+ cb: Callback<[len: number]>
1153
+ ): void
1154
+
1155
+ export function write(fd: number, data: string, pos: number, cb: Callback<[len: number]>): void
1156
+
1157
+ export function write(fd: number, data: Buffer | ArrayBufferView, cb: Callback<[len: number]>): void
1158
+
1159
+ export function write(fd: number, data: string, cb: Callback<[len: number]>): void
1160
+
1161
+ export function writeSync(
1162
+ fd: number,
1163
+ data: Buffer | ArrayBufferView,
1164
+ offset?: number,
1165
+ len?: number,
1166
+ pos?: number
1167
+ ): number
1168
+
1169
+ export function writeSync(fd: number, data: string, pos?: number, encoding?: BufferEncoding): number
1170
+
1171
+ export interface WriteFileOptions {
1172
+ encoding?: BufferEncoding
1173
+ flag?: Flag
1174
+ mode?: number
1175
+ }
1176
+
1177
+ export function writeFile(
1178
+ filepath: Path,
1179
+ data: string | Buffer | ArrayBufferView,
1180
+ opts?: WriteFileOptions
1181
+ ): Promise<void>
1182
+
1183
+ export function writeFile(
1184
+ filepath: Path,
1185
+ data: string | Buffer | ArrayBufferView,
1186
+ encoding: BufferEncoding
1187
+ ): Promise<void>
1188
+
1189
+ export function writeFile(
1190
+ filepath: Path,
1191
+ data: string | Buffer | ArrayBufferView,
1192
+ opts: WriteFileOptions,
1193
+ cb: Callback
1194
+ ): void
1195
+
1196
+ export function writeFile(
1197
+ filepath: Path,
1198
+ data: string | Buffer | ArrayBufferView,
1199
+ encoding: BufferEncoding,
1200
+ cb: Callback
1201
+ ): void
1202
+
1203
+ export function writeFile(
1204
+ filepath: Path,
1205
+ data: string | Buffer | ArrayBufferView,
1206
+ cb: Callback
1207
+ ): void
1208
+
1209
+ export function writeFileSync(
1210
+ filepath: Path,
1211
+ data: string | Buffer | ArrayBufferView,
1212
+ opts?: WriteFileOptions
1213
+ ): void
1214
+
1215
+ export function writeFileSync(
1216
+ filepath: Path,
1217
+ data: string | Buffer | ArrayBufferView,
1218
+ encoding: BufferEncoding
1219
+ ): void
1220
+
1221
+ export function writev(fd: number, buffers: ArrayBufferView[], pos?: number): Promise<number>
1222
+
1223
+ export function writev(
1224
+ fd: number,
1225
+ buffers: ArrayBufferView[],
1226
+ pos: number,
1227
+ cb: Callback<[len: number]>
1228
+ ): void
1229
+
1230
+ export function writev(fd: number, buffers: ArrayBufferView[], cb: Callback<[len: number]>): void
1231
+
1232
+ export function writevSync(fd: number, buffers: ArrayBufferView[], pos?: number): number
node_modules/bare-fs/index.js ADDED
@@ -0,0 +1,2842 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const FIFO = require('fast-fifo')
2
+ const EventEmitter = require('bare-events')
3
+ const path = require('bare-path')
4
+ const { isURL, fileURLToPath } = require('bare-url')
5
+ const { Readable, Writable } = require('bare-stream')
6
+ const binding = require('./binding')
7
+ const constants = require('./lib/constants')
8
+ const FileError = require('./lib/errors')
9
+
10
+ const isWindows = Bare.platform === 'win32'
11
+
12
+ exports.constants = constants
13
+
14
+ class FileRequest {
15
+ static borrow() {
16
+ if (this._free.length > 0) return this._free.pop()
17
+ return new FileRequest()
18
+ }
19
+
20
+ static return(req) {
21
+ if (this._free.length < 32) this._free.push(req.reset())
22
+ else req.destroy()
23
+ }
24
+
25
+ constructor() {
26
+ this._reset()
27
+ this._handle = binding.requestInit(this, this._onresult)
28
+ }
29
+
30
+ get handle() {
31
+ return this._handle
32
+ }
33
+
34
+ retain(value) {
35
+ this._retain = value // Tie the lifetime of `value` to the lifetime of `this`
36
+ }
37
+
38
+ reset() {
39
+ if (this._handle === null) return this
40
+
41
+ binding.requestReset(this._handle)
42
+
43
+ this._reset()
44
+
45
+ return this
46
+ }
47
+
48
+ destroy() {
49
+ if (this._handle === null) return this
50
+
51
+ binding.requestDestroy(this._handle)
52
+
53
+ this._reset()
54
+ this._handle = null
55
+
56
+ return this
57
+ }
58
+
59
+ then(resolve, reject) {
60
+ return this._promise.then(resolve, reject)
61
+ }
62
+
63
+ return() {
64
+ if (this._handle === null) return this
65
+
66
+ FileRequest.return(this)
67
+
68
+ return this
69
+ }
70
+
71
+ _reset() {
72
+ this._promise = new Promise((resolve, reject) => {
73
+ this._resolve = resolve
74
+ this._reject = reject
75
+ })
76
+ this._retain = null
77
+ }
78
+
79
+ _onresult(err, status) {
80
+ if (err) this._reject(err)
81
+ else this._resolve(status)
82
+ }
83
+ }
84
+
85
+ FileRequest._free = []
86
+
87
+ function ok(result, cb) {
88
+ if (typeof result === 'function') {
89
+ cb = result
90
+ result = undefined
91
+ }
92
+
93
+ if (cb) cb(null, result)
94
+ else return result
95
+ }
96
+
97
+ function fail(err, cb) {
98
+ if (cb) cb(err)
99
+ else throw err
100
+ }
101
+
102
+ function done(err, result, cb) {
103
+ if (typeof result === 'function') {
104
+ cb = result
105
+ result = undefined
106
+ }
107
+
108
+ if (err) fail(err, cb)
109
+ else return ok(result, cb)
110
+ }
111
+
112
+ async function open(filepath, flags = 'r', mode = 0o666, cb) {
113
+ if (typeof flags === 'function') {
114
+ cb = flags
115
+ flags = 'r'
116
+ mode = 0o666
117
+ } else if (typeof mode === 'function') {
118
+ cb = mode
119
+ mode = 0o666
120
+ }
121
+
122
+ if (typeof flags === 'string') flags = toFlags(flags)
123
+ if (typeof mode === 'string') mode = toMode(mode)
124
+
125
+ filepath = toNamespacedPath(filepath)
126
+
127
+ const req = FileRequest.borrow()
128
+
129
+ let fd
130
+ let err = null
131
+ try {
132
+ binding.open(req.handle, filepath, flags, mode)
133
+
134
+ fd = await req
135
+ } catch (e) {
136
+ err = new FileError(e.message, {
137
+ operation: 'open',
138
+ code: e.code,
139
+ path: filepath
140
+ })
141
+ } finally {
142
+ req.return()
143
+ }
144
+
145
+ return done(err, fd, cb)
146
+ }
147
+
148
+ function openSync(filepath, flags = 'r', mode = 0o666) {
149
+ if (typeof flags === 'string') flags = toFlags(flags)
150
+ if (typeof mode === 'string') mode = toMode(mode)
151
+
152
+ filepath = toNamespacedPath(filepath)
153
+
154
+ const req = FileRequest.borrow()
155
+
156
+ try {
157
+ return binding.openSync(req.handle, filepath, flags, mode)
158
+ } catch (e) {
159
+ throw new FileError(e.message, {
160
+ operation: 'open',
161
+ code: e.code,
162
+ path: filepath
163
+ })
164
+ } finally {
165
+ req.return()
166
+ }
167
+ }
168
+
169
+ async function close(fd, cb) {
170
+ const req = FileRequest.borrow()
171
+
172
+ let err = null
173
+ try {
174
+ binding.close(req.handle, fd)
175
+
176
+ await req
177
+ } catch (e) {
178
+ err = new FileError(e.message, { operation: 'close', code: e.code, fd })
179
+ } finally {
180
+ req.return()
181
+ }
182
+
183
+ return done(err, cb)
184
+ }
185
+
186
+ function closeSync(fd) {
187
+ const req = FileRequest.borrow()
188
+
189
+ try {
190
+ binding.closeSync(req.handle, fd)
191
+ } catch (e) {
192
+ throw new FileError(e.message, { operation: 'close', code: e.code, fd })
193
+ } finally {
194
+ req.return()
195
+ }
196
+ }
197
+
198
+ async function access(filepath, mode = constants.F_OK, cb) {
199
+ if (typeof mode === 'function') {
200
+ cb = mode
201
+ mode = constants.F_OK
202
+ }
203
+
204
+ filepath = toNamespacedPath(filepath)
205
+
206
+ const req = FileRequest.borrow()
207
+
208
+ let err = null
209
+ try {
210
+ binding.access(req.handle, filepath, mode)
211
+
212
+ await req
213
+ } catch (e) {
214
+ err = new FileError(e.message, {
215
+ operation: 'access',
216
+ code: e.code,
217
+ path: filepath
218
+ })
219
+ } finally {
220
+ req.return()
221
+ }
222
+
223
+ return done(err, cb)
224
+ }
225
+
226
+ function accessSync(filepath, mode = constants.F_OK) {
227
+ filepath = toNamespacedPath(filepath)
228
+
229
+ const req = FileRequest.borrow()
230
+
231
+ try {
232
+ binding.accessSync(req.handle, filepath, mode)
233
+ } catch (e) {
234
+ throw new FileError(e.message, {
235
+ operation: 'access',
236
+ code: e.code,
237
+ path: filepath
238
+ })
239
+ } finally {
240
+ req.return()
241
+ }
242
+ }
243
+
244
+ async function exists(filepath, cb) {
245
+ let ok = true
246
+ try {
247
+ await access(filepath)
248
+ } catch {
249
+ ok = false
250
+ }
251
+
252
+ return done(null, ok, cb)
253
+ }
254
+
255
+ function existsSync(filepath) {
256
+ try {
257
+ accessSync(filepath)
258
+ } catch {
259
+ return false
260
+ }
261
+
262
+ return true
263
+ }
264
+
265
+ async function read(fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1, cb) {
266
+ if (typeof offset === 'function') {
267
+ cb = offset
268
+ offset = 0
269
+ len = buffer.byteLength
270
+ pos = -1
271
+ } else if (typeof len === 'function') {
272
+ cb = len
273
+ len = buffer.byteLength - offset
274
+ pos = -1
275
+ } else if (typeof pos === 'function') {
276
+ cb = pos
277
+ pos = -1
278
+ }
279
+
280
+ if (typeof pos !== 'number') pos = -1
281
+
282
+ const req = FileRequest.borrow()
283
+
284
+ let bytes
285
+ let err = null
286
+ try {
287
+ binding.read(req.handle, fd, buffer, offset, len, pos)
288
+
289
+ req.retain(buffer)
290
+
291
+ bytes = await req
292
+ } catch (e) {
293
+ err = new FileError(e.message, { operation: 'read', code: e.code, fd })
294
+ } finally {
295
+ req.return()
296
+ }
297
+
298
+ return done(err, bytes, cb)
299
+ }
300
+
301
+ function readSync(fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1) {
302
+ const req = FileRequest.borrow()
303
+
304
+ try {
305
+ return binding.readSync(req.handle, fd, buffer, offset, len, pos)
306
+ } catch (e) {
307
+ throw new FileError(e.message, { operation: 'read', code: e.code, fd })
308
+ } finally {
309
+ req.return()
310
+ }
311
+ }
312
+
313
+ async function readv(fd, buffers, pos = -1, cb) {
314
+ if (typeof pos === 'function') {
315
+ cb = pos
316
+ pos = -1
317
+ }
318
+
319
+ if (typeof pos !== 'number') pos = -1
320
+
321
+ const req = FileRequest.borrow()
322
+
323
+ let bytes
324
+ let err = null
325
+ try {
326
+ binding.readv(req.handle, fd, buffers, pos)
327
+
328
+ req.retain(buffers)
329
+
330
+ bytes = await req
331
+ } catch (e) {
332
+ err = new FileError(e.message, { operation: 'readv', code: e.code, fd })
333
+ } finally {
334
+ req.return()
335
+ }
336
+
337
+ return done(err, bytes, cb)
338
+ }
339
+
340
+ function readvSync(fd, buffers, pos = -1) {
341
+ if (typeof pos !== 'number') pos = -1
342
+
343
+ const req = FileRequest.borrow()
344
+
345
+ try {
346
+ return binding.readvSync(req.handle, fd, buffers, pos)
347
+ } catch (e) {
348
+ throw new FileError(e.message, { operation: 'readv', code: e.code, fd })
349
+ } finally {
350
+ req.return()
351
+ }
352
+ }
353
+
354
+ async function write(fd, data, offset, len, pos = -1, cb) {
355
+ if (typeof data === 'string') {
356
+ let encoding = len
357
+ cb = pos
358
+ pos = offset
359
+
360
+ if (typeof pos === 'function') {
361
+ cb = pos
362
+ pos = -1
363
+ encoding = 'utf8'
364
+ } else if (typeof encoding === 'function') {
365
+ cb = encoding
366
+ encoding = 'utf8'
367
+ }
368
+
369
+ if (typeof pos === 'string') {
370
+ encoding = pos
371
+ pos = -1
372
+ }
373
+
374
+ data = Buffer.from(data, encoding)
375
+ offset = 0
376
+ len = data.byteLength
377
+ } else if (typeof offset === 'function') {
378
+ cb = offset
379
+ offset = 0
380
+ len = data.byteLength
381
+ pos = -1
382
+ } else if (typeof len === 'function') {
383
+ cb = len
384
+ len = data.byteLength - offset
385
+ pos = -1
386
+ } else if (typeof pos === 'function') {
387
+ cb = pos
388
+ pos = -1
389
+ }
390
+
391
+ if (typeof offset !== 'number') offset = 0
392
+ if (typeof len !== 'number') len = data.byteLength - offset
393
+ if (typeof pos !== 'number') pos = -1
394
+
395
+ const req = FileRequest.borrow()
396
+
397
+ let bytes
398
+ let err = null
399
+ try {
400
+ binding.write(req.handle, fd, data, offset, len, pos)
401
+
402
+ req.retain(data)
403
+
404
+ bytes = await req
405
+ } catch (e) {
406
+ err = new FileError(e.message, { operation: 'write', code: e.code, fd })
407
+ } finally {
408
+ req.return()
409
+ }
410
+
411
+ return done(err, bytes, cb)
412
+ }
413
+
414
+ function writeSync(fd, data, offset, len, pos = -1) {
415
+ if (typeof data === 'string') {
416
+ let encoding = len
417
+ pos = offset
418
+
419
+ if (typeof pos === 'string') {
420
+ encoding = pos
421
+ pos = -1
422
+ }
423
+
424
+ data = Buffer.from(data, encoding)
425
+ offset = 0
426
+ len = data.byteLength
427
+ }
428
+
429
+ if (typeof offset !== 'number') offset = 0
430
+ if (typeof len !== 'number') len = data.byteLength - offset
431
+ if (typeof pos !== 'number') pos = -1
432
+
433
+ const req = FileRequest.borrow()
434
+
435
+ try {
436
+ return binding.writeSync(req.handle, fd, data, offset, len, pos)
437
+ } catch (e) {
438
+ throw new FileError(e.message, { operation: 'write', code: e.code, fd })
439
+ } finally {
440
+ req.return()
441
+ }
442
+ }
443
+
444
+ async function writev(fd, buffers, pos = -1, cb) {
445
+ if (typeof pos === 'function') {
446
+ cb = pos
447
+ pos = -1
448
+ }
449
+
450
+ if (typeof pos !== 'number') pos = -1
451
+
452
+ const req = FileRequest.borrow()
453
+
454
+ let bytes
455
+ let err = null
456
+ try {
457
+ binding.writev(req.handle, fd, buffers, pos)
458
+
459
+ req.retain(buffers)
460
+
461
+ bytes = await req
462
+ } catch (e) {
463
+ err = new FileError(e.message, { operation: 'writev', code: e.code, fd })
464
+ } finally {
465
+ req.return()
466
+ }
467
+
468
+ return done(err, bytes, cb)
469
+ }
470
+
471
+ function writevSync(fd, buffers, pos = -1) {
472
+ if (typeof pos !== 'number') pos = -1
473
+
474
+ const req = FileRequest.borrow()
475
+
476
+ try {
477
+ return binding.writevSync(req.handle, fd, buffers, pos)
478
+ } catch (e) {
479
+ throw new FileError(e.message, { operation: 'writev', code: e.code, fd })
480
+ } finally {
481
+ req.return()
482
+ }
483
+ }
484
+
485
+ async function stat(filepath, cb) {
486
+ filepath = toNamespacedPath(filepath)
487
+
488
+ const req = FileRequest.borrow()
489
+
490
+ let st
491
+ let err = null
492
+ try {
493
+ binding.stat(req.handle, filepath)
494
+
495
+ await req
496
+
497
+ st = new Stats(...binding.requestResultStat(req.handle))
498
+ } catch (e) {
499
+ err = new FileError(e.message, { operation: 'stat', code: e.code, path: filepath })
500
+ } finally {
501
+ req.return()
502
+ }
503
+
504
+ return done(err, st, cb)
505
+ }
506
+
507
+ function statSync(filepath) {
508
+ filepath = toNamespacedPath(filepath)
509
+
510
+ const req = FileRequest.borrow()
511
+
512
+ try {
513
+ binding.statSync(req.handle, filepath)
514
+
515
+ return new Stats(...binding.requestResultStat(req.handle))
516
+ } catch (e) {
517
+ throw new FileError(e.message, { operation: 'stat', code: e.code, path: filepath })
518
+ } finally {
519
+ req.return()
520
+ }
521
+ }
522
+
523
+ async function lstat(filepath, cb) {
524
+ filepath = toNamespacedPath(filepath)
525
+
526
+ const req = FileRequest.borrow()
527
+
528
+ let st
529
+ let err = null
530
+ try {
531
+ binding.lstat(req.handle, filepath)
532
+
533
+ await req
534
+
535
+ st = new Stats(...binding.requestResultStat(req.handle))
536
+ } catch (e) {
537
+ err = new FileError(e.message, { operation: 'lstat', code: e.code, path: filepath })
538
+ } finally {
539
+ req.return()
540
+ }
541
+
542
+ return done(err, st, cb)
543
+ }
544
+
545
+ function lstatSync(filepath) {
546
+ filepath = toNamespacedPath(filepath)
547
+
548
+ const req = FileRequest.borrow()
549
+
550
+ try {
551
+ binding.lstatSync(req.handle, filepath)
552
+
553
+ return new Stats(...binding.requestResultStat(req.handle))
554
+ } catch (e) {
555
+ throw new FileError(e.message, { operation: 'lstat', code: e.code, path: filepath })
556
+ } finally {
557
+ req.return()
558
+ }
559
+ }
560
+
561
+ async function fstat(fd, cb) {
562
+ const req = FileRequest.borrow()
563
+
564
+ let st
565
+ let err = null
566
+ try {
567
+ binding.fstat(req.handle, fd)
568
+
569
+ await req
570
+
571
+ st = new Stats(...binding.requestResultStat(req.handle))
572
+ } catch (e) {
573
+ err = new FileError(e.message, { operation: 'fstat', code: e.code, fd })
574
+ } finally {
575
+ req.return()
576
+ }
577
+
578
+ return done(err, st, cb)
579
+ }
580
+
581
+ function fstatSync(fd) {
582
+ const req = FileRequest.borrow()
583
+
584
+ try {
585
+ binding.fstatSync(req.handle, fd)
586
+
587
+ return new Stats(...binding.requestResultStat(req.handle))
588
+ } catch (e) {
589
+ throw new FileError(e.message, { operation: 'fstat', code: e.code, fd })
590
+ } finally {
591
+ req.return()
592
+ }
593
+ }
594
+
595
+ async function statfs(filepath, cb) {
596
+ filepath = toNamespacedPath(filepath)
597
+
598
+ const req = FileRequest.borrow()
599
+
600
+ let st
601
+ let err = null
602
+ try {
603
+ binding.statfs(req.handle, filepath)
604
+
605
+ await req
606
+
607
+ st = new StatFs(...binding.requestResultStatfs(req.handle))
608
+ } catch (e) {
609
+ err = new FileError(e.message, { operation: 'statfs', code: e.code, path: filepath })
610
+ } finally {
611
+ req.return()
612
+ }
613
+
614
+ return done(err, st, cb)
615
+ }
616
+
617
+ function statfsSync(filepath) {
618
+ filepath = toNamespacedPath(filepath)
619
+
620
+ const req = FileRequest.borrow()
621
+
622
+ try {
623
+ binding.statfsSync(req.handle, filepath)
624
+
625
+ return new StatFs(...binding.requestResultStatfs(req.handle))
626
+ } catch (e) {
627
+ throw new FileError(e.message, { operation: 'statfs', code: e.code, path: filepath })
628
+ } finally {
629
+ req.return()
630
+ }
631
+ }
632
+
633
+ async function ftruncate(fd, len = 0, cb) {
634
+ if (typeof len === 'function') {
635
+ cb = len
636
+ len = 0
637
+ }
638
+
639
+ if (typeof len !== 'number') len = 0
640
+
641
+ const req = FileRequest.borrow()
642
+
643
+ let err = null
644
+ try {
645
+ binding.ftruncate(req.handle, fd, len)
646
+
647
+ await req
648
+ } catch (e) {
649
+ err = new FileError(e.message, { operation: 'ftruncate', code: e.code, fd })
650
+ } finally {
651
+ req.return()
652
+ }
653
+
654
+ return done(err, cb)
655
+ }
656
+
657
+ function ftruncateSync(fd, len = 0) {
658
+ if (typeof len !== 'number') len = 0
659
+
660
+ const req = FileRequest.borrow()
661
+
662
+ try {
663
+ binding.ftruncateSync(req.handle, fd, len)
664
+ } catch (e) {
665
+ throw new FileError(e.message, { operation: 'ftruncate', code: e.code, fd })
666
+ } finally {
667
+ req.return()
668
+ }
669
+ }
670
+
671
+ async function truncate(filepath, len, cb) {
672
+ let fd = -1
673
+ let err
674
+
675
+ try {
676
+ fd = await open(filepath, 'r+')
677
+
678
+ await ftruncate(fd, len)
679
+ } catch (e) {
680
+ err = e
681
+ } finally {
682
+ if (fd !== -1) await close(fd)
683
+ }
684
+
685
+ return done(err, cb)
686
+ }
687
+
688
+ function truncateSync(filepath, len) {
689
+ let fd = -1
690
+ let err
691
+
692
+ try {
693
+ fd = openSync(filepath, 'r+')
694
+
695
+ ftruncateSync(fd, len)
696
+ } catch (e) {
697
+ err = e
698
+ } finally {
699
+ if (fd !== -1) closeSync(fd)
700
+ }
701
+ }
702
+
703
+ async function chmod(filepath, mode, cb) {
704
+ if (typeof mode === 'string') mode = toMode(mode)
705
+
706
+ filepath = toNamespacedPath(filepath)
707
+
708
+ const req = FileRequest.borrow()
709
+
710
+ let err = null
711
+ try {
712
+ binding.chmod(req.handle, filepath, mode)
713
+
714
+ await req
715
+ } catch (e) {
716
+ err = new FileError(e.message, {
717
+ operation: 'chmod',
718
+ code: e.code,
719
+ path: filepath
720
+ })
721
+ } finally {
722
+ req.return()
723
+ }
724
+
725
+ return done(err, cb)
726
+ }
727
+
728
+ function chmodSync(filepath, mode) {
729
+ if (typeof mode === 'string') mode = toMode(mode)
730
+
731
+ filepath = toNamespacedPath(filepath)
732
+
733
+ const req = FileRequest.borrow()
734
+
735
+ try {
736
+ binding.chmodSync(req.handle, filepath, mode)
737
+ } catch (e) {
738
+ throw new FileError(e.message, {
739
+ operation: 'chmod',
740
+ code: e.code,
741
+ path: filepath
742
+ })
743
+ } finally {
744
+ req.return()
745
+ }
746
+ }
747
+
748
+ async function fchmod(fd, mode, cb) {
749
+ if (typeof mode === 'string') mode = toMode(mode)
750
+
751
+ const req = FileRequest.borrow()
752
+
753
+ let err = null
754
+ try {
755
+ binding.fchmod(req.handle, fd, mode)
756
+
757
+ await req
758
+ } catch (e) {
759
+ err = new FileError(e.message, { operation: 'fchmod', code: e.code, fd })
760
+ } finally {
761
+ req.return()
762
+ }
763
+
764
+ return done(err, cb)
765
+ }
766
+
767
+ function fchmodSync(fd, mode) {
768
+ if (typeof mode === 'string') mode = toMode(mode)
769
+
770
+ const req = FileRequest.borrow()
771
+
772
+ try {
773
+ binding.fchmodSync(req.handle, fd, mode)
774
+ } catch (e) {
775
+ throw new FileError(e.message, { operation: 'fchmod', code: e.code, fd })
776
+ } finally {
777
+ req.return()
778
+ }
779
+ }
780
+
781
+ async function chown(filepath, uid, gid, cb) {
782
+ filepath = toNamespacedPath(filepath)
783
+
784
+ const req = FileRequest.borrow()
785
+
786
+ let err = null
787
+ try {
788
+ binding.chown(req.handle, filepath, uid, gid)
789
+
790
+ await req
791
+ } catch (e) {
792
+ err = new FileError(e.message, { operation: 'chown', code: e.code, path: filepath })
793
+ } finally {
794
+ req.return()
795
+ }
796
+
797
+ return done(err, cb)
798
+ }
799
+
800
+ function chownSync(filepath, uid, gid) {
801
+ filepath = toNamespacedPath(filepath)
802
+
803
+ const req = FileRequest.borrow()
804
+
805
+ try {
806
+ binding.chownSync(req.handle, filepath, uid, gid)
807
+ } catch (e) {
808
+ throw new FileError(e.message, { operation: 'chownSync', code: e.code, path: filepath })
809
+ } finally {
810
+ req.return()
811
+ }
812
+ }
813
+
814
+ async function lchown(filepath, uid, gid, cb) {
815
+ filepath = toNamespacedPath(filepath)
816
+
817
+ const req = FileRequest.borrow()
818
+
819
+ let err = null
820
+ try {
821
+ binding.lchown(req.handle, filepath, uid, gid)
822
+
823
+ await req
824
+ } catch (e) {
825
+ err = new FileError(e.message, { operation: 'lchown', code: e.code, path: filepath })
826
+ } finally {
827
+ req.return()
828
+ }
829
+
830
+ return done(err, cb)
831
+ }
832
+
833
+ function lchownSync(filepath, uid, gid) {
834
+ filepath = toNamespacedPath(filepath)
835
+
836
+ const req = FileRequest.borrow()
837
+
838
+ try {
839
+ binding.lchownSync(req.handle, filepath, uid, gid)
840
+ } catch (e) {
841
+ throw new FileError(e.message, { operation: 'lchownSync', code: e.code, path: filepath })
842
+ } finally {
843
+ req.return()
844
+ }
845
+ }
846
+
847
+ async function fchown(fd, uid, gid, cb) {
848
+ const req = FileRequest.borrow()
849
+
850
+ let err = null
851
+ try {
852
+ binding.fchown(req.handle, fd, uid, gid)
853
+
854
+ await req
855
+ } catch (e) {
856
+ err = new FileError(e.message, { operation: 'fchown', code: e.code, fd })
857
+ } finally {
858
+ req.return()
859
+ }
860
+
861
+ return done(err, cb)
862
+ }
863
+
864
+ function fchownSync(fd, uid, gid) {
865
+ const req = FileRequest.borrow()
866
+
867
+ try {
868
+ binding.fchownSync(req.handle, fd, uid, gid)
869
+ } catch (e) {
870
+ throw new FileError(e.message, { operation: 'fchownSync', code: e.code, fd })
871
+ } finally {
872
+ req.return()
873
+ }
874
+ }
875
+
876
+ async function utimes(filepath, atime, mtime, cb) {
877
+ if (typeof atime !== 'number') atime = atime.getTime() / 1000
878
+ if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
879
+
880
+ filepath = toNamespacedPath(filepath)
881
+
882
+ const req = FileRequest.borrow()
883
+
884
+ let err = null
885
+ try {
886
+ binding.utimes(req.handle, filepath, atime, mtime)
887
+
888
+ await req
889
+ } catch (e) {
890
+ err = new FileError(e.message, { operation: 'utimes', code: e.code, path: filepath })
891
+ } finally {
892
+ req.return()
893
+ }
894
+
895
+ return done(err, cb)
896
+ }
897
+
898
+ function utimesSync(filepath, atime, mtime) {
899
+ if (typeof atime !== 'number') atime = atime.getTime() / 1000
900
+ if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
901
+
902
+ filepath = toNamespacedPath(filepath)
903
+
904
+ const req = FileRequest.borrow()
905
+
906
+ try {
907
+ binding.utimesSync(req.handle, filepath, atime, mtime)
908
+ } catch (e) {
909
+ throw new FileError(e.message, { operation: 'utimes', code: e.code, path: filepath })
910
+ } finally {
911
+ req.return()
912
+ }
913
+ }
914
+
915
+ async function lutimes(filepath, atime, mtime, cb) {
916
+ if (typeof atime !== 'number') atime = atime.getTime() / 1000
917
+ if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
918
+
919
+ filepath = toNamespacedPath(filepath)
920
+
921
+ const req = FileRequest.borrow()
922
+
923
+ let err = null
924
+ try {
925
+ binding.lutimes(req.handle, filepath, atime, mtime)
926
+
927
+ await req
928
+ } catch (e) {
929
+ err = new FileError(e.message, { operation: 'lutimes', code: e.code, path: filepath })
930
+ } finally {
931
+ req.return()
932
+ }
933
+
934
+ return done(err, cb)
935
+ }
936
+
937
+ function lutimesSync(filepath, atime, mtime) {
938
+ if (typeof atime !== 'number') atime = atime.getTime() / 1000
939
+ if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
940
+
941
+ filepath = toNamespacedPath(filepath)
942
+
943
+ const req = FileRequest.borrow()
944
+
945
+ try {
946
+ binding.lutimesSync(req.handle, filepath, atime, mtime)
947
+ } catch (e) {
948
+ throw new FileError(e.message, { operation: 'lutimes', code: e.code, path: filepath })
949
+ } finally {
950
+ req.return()
951
+ }
952
+ }
953
+
954
+ async function futimes(fd, atime, mtime, cb) {
955
+ if (typeof atime !== 'number') atime = atime.getTime() / 1000
956
+ if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
957
+
958
+ const req = FileRequest.borrow()
959
+
960
+ let err = null
961
+ try {
962
+ binding.futimes(req.handle, fd, atime, mtime)
963
+
964
+ await req
965
+ } catch (e) {
966
+ err = new FileError(e.message, { operation: 'futimes', code: e.code, fd })
967
+ } finally {
968
+ req.return()
969
+ }
970
+
971
+ return done(err, cb)
972
+ }
973
+
974
+ function futimesSync(fd, atime, mtime) {
975
+ if (typeof atime !== 'number') atime = atime.getTime() / 1000
976
+ if (typeof mtime !== 'number') mtime = mtime.getTime() / 1000
977
+
978
+ const req = FileRequest.borrow()
979
+
980
+ try {
981
+ binding.futimesSync(req.handle, fd, atime, mtime)
982
+ } catch (e) {
983
+ throw new FileError(e.message, { operation: 'futimesSync', code: e.code, fd })
984
+ } finally {
985
+ req.return()
986
+ }
987
+ }
988
+
989
+ async function link(src, dst, cb) {
990
+ src = toNamespacedPath(src)
991
+ dst = toNamespacedPath(dst)
992
+
993
+ const req = FileRequest.borrow()
994
+
995
+ let err = null
996
+ try {
997
+ binding.link(req.handle, src, dst)
998
+
999
+ await req
1000
+ } catch (e) {
1001
+ err = new FileError(e.message, { operation: 'link', code: e.code, path: src, destination: dst })
1002
+ } finally {
1003
+ req.return()
1004
+ }
1005
+
1006
+ return done(err, cb)
1007
+ }
1008
+
1009
+ function linkSync(src, dst) {
1010
+ src = toNamespacedPath(src)
1011
+ dst = toNamespacedPath(dst)
1012
+
1013
+ const req = FileRequest.borrow()
1014
+
1015
+ try {
1016
+ binding.linkSync(req.handle, src, dst)
1017
+ } catch (e) {
1018
+ throw new FileError(e.message, {
1019
+ operation: 'linkSync',
1020
+ code: e.code,
1021
+ path: src,
1022
+ destination: dst
1023
+ })
1024
+ } finally {
1025
+ req.return()
1026
+ }
1027
+ }
1028
+
1029
+ async function mkdir(filepath, opts, cb) {
1030
+ if (typeof opts === 'function') {
1031
+ cb = opts
1032
+ opts = { mode: 0o777 }
1033
+ }
1034
+
1035
+ if (typeof opts === 'number') opts = { mode: opts }
1036
+ else if (!opts) opts = {}
1037
+
1038
+ const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
1039
+
1040
+ filepath = toNamespacedPath(filepath)
1041
+
1042
+ if (opts.recursive) {
1043
+ let err = null
1044
+ try {
1045
+ try {
1046
+ await mkdir(filepath, { mode })
1047
+ } catch (err) {
1048
+ if (err.code !== 'ENOENT') {
1049
+ if (!(await stat(filepath)).isDirectory()) throw err
1050
+ } else {
1051
+ while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
1052
+ const i = filepath.lastIndexOf(path.sep)
1053
+ if (i <= 0) throw err
1054
+
1055
+ await mkdir(filepath.slice(0, i), { mode, recursive: true })
1056
+
1057
+ try {
1058
+ await mkdir(filepath, { mode })
1059
+ } catch (err) {
1060
+ if (!(await stat(filepath)).isDirectory()) throw err
1061
+ }
1062
+ }
1063
+ }
1064
+ } catch (e) {
1065
+ err = e
1066
+ }
1067
+
1068
+ return done(err, cb)
1069
+ }
1070
+
1071
+ const req = FileRequest.borrow()
1072
+
1073
+ let err = null
1074
+ try {
1075
+ binding.mkdir(req.handle, filepath, mode)
1076
+
1077
+ await req
1078
+ } catch (e) {
1079
+ err = new FileError(e.message, {
1080
+ operation: 'mkdir',
1081
+ code: e.code,
1082
+ path: filepath
1083
+ })
1084
+ } finally {
1085
+ req.return()
1086
+ }
1087
+
1088
+ return done(err, cb)
1089
+ }
1090
+
1091
+ function mkdirSync(filepath, opts) {
1092
+ if (typeof opts === 'number') opts = { mode: opts }
1093
+ else if (!opts) opts = {}
1094
+
1095
+ const mode = typeof opts.mode === 'number' ? opts.mode : 0o777
1096
+
1097
+ filepath = toNamespacedPath(filepath)
1098
+
1099
+ if (opts.recursive) {
1100
+ try {
1101
+ mkdirSync(filepath, { mode })
1102
+ } catch (err) {
1103
+ if (err.code !== 'ENOENT') {
1104
+ if (!statSync(filepath).isDirectory()) throw err
1105
+ } else {
1106
+ while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
1107
+ const i = filepath.lastIndexOf(path.sep)
1108
+ if (i <= 0) throw err
1109
+
1110
+ mkdirSync(filepath.slice(0, i), { mode, recursive: true })
1111
+
1112
+ try {
1113
+ mkdirSync(filepath, { mode })
1114
+ } catch (err) {
1115
+ if (!statSync(filepath).isDirectory()) throw err
1116
+ }
1117
+ }
1118
+ }
1119
+
1120
+ return
1121
+ }
1122
+
1123
+ const req = FileRequest.borrow()
1124
+
1125
+ try {
1126
+ binding.mkdirSync(req.handle, filepath, mode)
1127
+ } catch (e) {
1128
+ throw new FileError(e.message, {
1129
+ operation: 'mkdir',
1130
+ code: e.code,
1131
+ path: filepath
1132
+ })
1133
+ } finally {
1134
+ req.return()
1135
+ }
1136
+ }
1137
+
1138
+ async function mkdtemp(prefix, cb) {
1139
+ prefix = toNamespacedPath(prefix)
1140
+
1141
+ const req = FileRequest.borrow()
1142
+
1143
+ let res
1144
+ let err = null
1145
+ try {
1146
+ binding.mkdtemp(req.handle, prefix + 'XXXXXX')
1147
+
1148
+ await req
1149
+
1150
+ res = binding.requestResultPath(req.handle)
1151
+ } catch (e) {
1152
+ err = new FileError(e.message, { operation: 'mkdtemp', code: e.code, path: prefix })
1153
+ } finally {
1154
+ req.return()
1155
+ }
1156
+
1157
+ return done(err, res, cb)
1158
+ }
1159
+
1160
+ function mkdtempSync(prefix) {
1161
+ prefix = toNamespacedPath(prefix)
1162
+
1163
+ const req = FileRequest.borrow()
1164
+
1165
+ try {
1166
+ binding.mkdtempSync(req.handle, prefix + 'XXXXXX')
1167
+
1168
+ return binding.requestResultPath(req.handle)
1169
+ } catch (e) {
1170
+ throw new FileError(e.message, { operation: 'mkdtempSync', code: e.code, path: prefix })
1171
+ } finally {
1172
+ req.return()
1173
+ }
1174
+ }
1175
+
1176
+ async function rmdir(filepath, cb) {
1177
+ filepath = toNamespacedPath(filepath)
1178
+
1179
+ const req = FileRequest.borrow()
1180
+
1181
+ let err = null
1182
+ try {
1183
+ binding.rmdir(req.handle, filepath)
1184
+
1185
+ await req
1186
+ } catch (e) {
1187
+ err = new FileError(e.message, {
1188
+ operation: 'rmdir',
1189
+ code: e.code,
1190
+ path: filepath
1191
+ })
1192
+ } finally {
1193
+ req.return()
1194
+ }
1195
+
1196
+ return done(err, cb)
1197
+ }
1198
+
1199
+ function rmdirSync(filepath) {
1200
+ filepath = toNamespacedPath(filepath)
1201
+
1202
+ const req = FileRequest.borrow()
1203
+
1204
+ try {
1205
+ binding.rmdirSync(req.handle, filepath)
1206
+ } catch (e) {
1207
+ throw new FileError(e.message, {
1208
+ operation: 'rmdir',
1209
+ code: e.code,
1210
+ path: filepath
1211
+ })
1212
+ } finally {
1213
+ req.return()
1214
+ }
1215
+ }
1216
+
1217
+ async function rm(filepath, opts, cb) {
1218
+ if (typeof opts === 'function') {
1219
+ cb = opts
1220
+ opts = {}
1221
+ }
1222
+
1223
+ if (!opts) opts = {}
1224
+
1225
+ filepath = toNamespacedPath(filepath)
1226
+
1227
+ let err = null
1228
+ try {
1229
+ const st = await lstat(filepath)
1230
+
1231
+ if (st.isDirectory()) {
1232
+ if (opts.recursive) {
1233
+ try {
1234
+ await rmdir(filepath)
1235
+ } catch (err) {
1236
+ if (err.code !== 'ENOTEMPTY') throw err
1237
+
1238
+ const files = await readdir(filepath)
1239
+
1240
+ for (const file of files) {
1241
+ await rm(filepath + path.sep + file, opts)
1242
+ }
1243
+
1244
+ await rmdir(filepath)
1245
+ }
1246
+ } else {
1247
+ throw new FileError('is a directory', {
1248
+ operation: 'rm',
1249
+ code: 'EISDIR',
1250
+ path: filepath
1251
+ })
1252
+ }
1253
+ } else {
1254
+ await unlink(filepath)
1255
+ }
1256
+ } catch (e) {
1257
+ if (e.code !== 'ENOENT' || !opts.force) err = e
1258
+ }
1259
+
1260
+ return done(err, cb)
1261
+ }
1262
+
1263
+ function rmSync(filepath, opts) {
1264
+ if (!opts) opts = {}
1265
+
1266
+ filepath = toNamespacedPath(filepath)
1267
+
1268
+ try {
1269
+ const st = lstatSync(filepath)
1270
+
1271
+ if (st.isDirectory()) {
1272
+ if (opts.recursive) {
1273
+ try {
1274
+ rmdirSync(filepath)
1275
+ } catch (err) {
1276
+ if (err.code !== 'ENOTEMPTY') throw err
1277
+
1278
+ const files = readdirSync(filepath)
1279
+
1280
+ for (const file of files) {
1281
+ rmSync(filepath + path.sep + file, opts)
1282
+ }
1283
+
1284
+ rmdirSync(filepath)
1285
+ }
1286
+ } else {
1287
+ throw new FileError('is a directory', {
1288
+ operation: 'rm',
1289
+ code: 'EISDIR',
1290
+ path: filepath
1291
+ })
1292
+ }
1293
+ } else {
1294
+ unlinkSync(filepath)
1295
+ }
1296
+ } catch (err) {
1297
+ if (err.code !== 'ENOENT' || !opts.force) throw err
1298
+ }
1299
+ }
1300
+
1301
+ async function unlink(filepath, cb) {
1302
+ filepath = toNamespacedPath(filepath)
1303
+
1304
+ const req = FileRequest.borrow()
1305
+
1306
+ let err = null
1307
+ try {
1308
+ binding.unlink(req.handle, filepath)
1309
+
1310
+ await req
1311
+ } catch (e) {
1312
+ err = new FileError(e.message, {
1313
+ operation: 'unlink',
1314
+ code: e.code,
1315
+ path: filepath
1316
+ })
1317
+ } finally {
1318
+ req.return()
1319
+ }
1320
+
1321
+ return done(err, cb)
1322
+ }
1323
+
1324
+ function unlinkSync(filepath) {
1325
+ filepath = toNamespacedPath(filepath)
1326
+
1327
+ const req = FileRequest.borrow()
1328
+
1329
+ try {
1330
+ binding.unlinkSync(req.handle, filepath)
1331
+ } catch (e) {
1332
+ throw new FileError(e.message, {
1333
+ operation: 'unlink',
1334
+ code: e.code,
1335
+ path: filepath
1336
+ })
1337
+ } finally {
1338
+ req.return()
1339
+ }
1340
+ }
1341
+
1342
+ async function rename(src, dst, cb) {
1343
+ src = toNamespacedPath(src)
1344
+ dst = toNamespacedPath(dst)
1345
+
1346
+ const req = FileRequest.borrow()
1347
+
1348
+ let err = null
1349
+ try {
1350
+ binding.rename(req.handle, src, dst)
1351
+
1352
+ await req
1353
+ } catch (e) {
1354
+ err = new FileError(e.message, {
1355
+ operation: 'rename',
1356
+ code: e.code,
1357
+ path: src,
1358
+ destination: dst
1359
+ })
1360
+ } finally {
1361
+ req.return()
1362
+ }
1363
+
1364
+ return done(err, cb)
1365
+ }
1366
+
1367
+ function renameSync(src, dst) {
1368
+ src = toNamespacedPath(src)
1369
+ dst = toNamespacedPath(dst)
1370
+
1371
+ const req = FileRequest.borrow()
1372
+
1373
+ try {
1374
+ binding.renameSync(req.handle, src, dst)
1375
+ } catch (e) {
1376
+ throw new FileError(e.message, {
1377
+ operation: 'rename',
1378
+ code: e.code,
1379
+ path: src,
1380
+ destination: dst
1381
+ })
1382
+ } finally {
1383
+ req.return()
1384
+ }
1385
+ }
1386
+
1387
+ async function copyFile(src, dst, mode = 0, cb) {
1388
+ if (typeof mode === 'function') {
1389
+ cb = mode
1390
+ mode = 0
1391
+ }
1392
+
1393
+ src = toNamespacedPath(src)
1394
+ dst = toNamespacedPath(dst)
1395
+
1396
+ const req = FileRequest.borrow()
1397
+
1398
+ let err = null
1399
+ try {
1400
+ binding.copyfile(req.handle, src, dst, mode)
1401
+
1402
+ await req
1403
+ } catch (e) {
1404
+ err = new FileError(e.message, {
1405
+ operation: 'copyfile',
1406
+ code: e.code,
1407
+ path: src,
1408
+ destination: dst
1409
+ })
1410
+ } finally {
1411
+ req.return()
1412
+ }
1413
+
1414
+ return done(err, cb)
1415
+ }
1416
+
1417
+ function copyFileSync(src, dst, mode = 0) {
1418
+ src = toNamespacedPath(src)
1419
+ dst = toNamespacedPath(dst)
1420
+
1421
+ const req = FileRequest.borrow()
1422
+
1423
+ try {
1424
+ binding.copyfileSync(req.handle, src, dst, mode)
1425
+ } catch (e) {
1426
+ throw new FileError(e.message, {
1427
+ operation: 'copyfile',
1428
+ code: e.code,
1429
+ path: src,
1430
+ destination: dst
1431
+ })
1432
+ } finally {
1433
+ req.return()
1434
+ }
1435
+ }
1436
+
1437
+ async function cp(src, dst, opts, cb) {
1438
+ if (typeof opts === 'function') {
1439
+ cb = opts
1440
+ opts = {}
1441
+ }
1442
+
1443
+ if (!opts) opts = {}
1444
+
1445
+ src = toNamespacedPath(src)
1446
+ dst = toNamespacedPath(dst)
1447
+
1448
+ let err = null
1449
+ try {
1450
+ const st = await lstat(src)
1451
+
1452
+ if (st.isDirectory()) {
1453
+ if (opts.recursive !== true) {
1454
+ throw new FileError('is a directory', { operation: 'cp', code: 'EISDIR', path: src })
1455
+ }
1456
+
1457
+ try {
1458
+ await lstat(dst)
1459
+ } catch (e) {
1460
+ if (e.code !== 'ENOENT') throw e
1461
+
1462
+ await mkdir(dst, { mode: st.mode, recursive: true })
1463
+ }
1464
+
1465
+ const dir = await opendir(src)
1466
+ for await (const { name } of dir) {
1467
+ await cp(path.join(src, name), path.join(dst, name), opts)
1468
+ }
1469
+ } else if (st.isFile()) {
1470
+ await copyFile(src, dst)
1471
+ await chmod(dst, st.mode)
1472
+ }
1473
+ } catch (e) {
1474
+ err = e
1475
+ }
1476
+
1477
+ return done(err, cb)
1478
+ }
1479
+
1480
+ function cpSync(src, dst, opts = {}) {
1481
+ src = toNamespacedPath(src)
1482
+ dst = toNamespacedPath(dst)
1483
+
1484
+ const st = lstatSync(src)
1485
+
1486
+ if (st.isDirectory()) {
1487
+ if (opts.recursive !== true) {
1488
+ throw new FileError('is a directory', { operation: 'cp', code: 'EISDIR', path: src })
1489
+ }
1490
+
1491
+ try {
1492
+ lstatSync(dst)
1493
+ } catch (e) {
1494
+ if (e.code !== 'ENOENT') throw e
1495
+
1496
+ mkdirSync(dst, { mode: st.mode, recursive: true })
1497
+ }
1498
+
1499
+ const dir = opendirSync(src)
1500
+ for (const { name } of dir) {
1501
+ cpSync(path.join(src, name), path.join(dst, name), opts)
1502
+ }
1503
+ } else if (st.isFile()) {
1504
+ copyFileSync(src, dst)
1505
+ chmodSync(dst, st.mode)
1506
+ }
1507
+ }
1508
+
1509
+ async function realpath(filepath, opts, cb) {
1510
+ if (typeof opts === 'function') {
1511
+ cb = opts
1512
+ opts = {}
1513
+ }
1514
+
1515
+ if (typeof opts === 'string') opts = { encoding: opts }
1516
+ else if (!opts) opts = {}
1517
+
1518
+ const { encoding = 'utf8' } = opts
1519
+
1520
+ filepath = toNamespacedPath(filepath)
1521
+
1522
+ const req = FileRequest.borrow()
1523
+
1524
+ let res
1525
+ let err = null
1526
+ try {
1527
+ binding.realpath(req.handle, filepath)
1528
+
1529
+ await req
1530
+
1531
+ res = Buffer.from(binding.requestResultString(req.handle))
1532
+
1533
+ if (encoding !== 'buffer') res = res.toString(encoding)
1534
+ } catch (e) {
1535
+ err = new FileError(e.message, {
1536
+ operation: 'realpath',
1537
+ code: e.code,
1538
+ path: filepath
1539
+ })
1540
+ } finally {
1541
+ req.return()
1542
+ }
1543
+
1544
+ return done(err, res, cb)
1545
+ }
1546
+
1547
+ function realpathSync(filepath, opts) {
1548
+ if (typeof opts === 'string') opts = { encoding: opts }
1549
+ else if (!opts) opts = {}
1550
+
1551
+ const { encoding = 'utf8' } = opts
1552
+
1553
+ filepath = toNamespacedPath(filepath)
1554
+
1555
+ const req = FileRequest.borrow()
1556
+
1557
+ try {
1558
+ binding.realpathSync(req.handle, filepath)
1559
+
1560
+ let res = Buffer.from(binding.requestResultString(req.handle))
1561
+
1562
+ if (encoding !== 'buffer') res = res.toString(encoding)
1563
+
1564
+ return res
1565
+ } catch (e) {
1566
+ throw new FileError(e.message, {
1567
+ operation: 'realpath',
1568
+ code: e.code,
1569
+ path: filepath
1570
+ })
1571
+ } finally {
1572
+ req.return()
1573
+ }
1574
+ }
1575
+
1576
+ async function readlink(filepath, opts, cb) {
1577
+ if (typeof opts === 'function') {
1578
+ cb = opts
1579
+ opts = {}
1580
+ }
1581
+
1582
+ if (typeof opts === 'string') opts = { encoding: opts }
1583
+ else if (!opts) opts = {}
1584
+
1585
+ const { encoding = 'utf8' } = opts
1586
+
1587
+ filepath = toNamespacedPath(filepath)
1588
+
1589
+ const req = FileRequest.borrow()
1590
+
1591
+ let res
1592
+ let err = null
1593
+ try {
1594
+ binding.readlink(req.handle, filepath)
1595
+
1596
+ await req
1597
+
1598
+ res = Buffer.from(binding.requestResultString(req.handle))
1599
+
1600
+ if (encoding !== 'buffer') res = res.toString(encoding)
1601
+ } catch (e) {
1602
+ err = new FileError(e.message, {
1603
+ operation: 'readlink',
1604
+ code: e.code,
1605
+ path: filepath
1606
+ })
1607
+ } finally {
1608
+ req.return()
1609
+ }
1610
+
1611
+ return done(err, res, cb)
1612
+ }
1613
+
1614
+ function readlinkSync(filepath, opts) {
1615
+ if (typeof opts === 'string') opts = { encoding: opts }
1616
+ else if (!opts) opts = {}
1617
+
1618
+ const { encoding = 'utf8' } = opts
1619
+
1620
+ filepath = toNamespacedPath(filepath)
1621
+
1622
+ const req = FileRequest.borrow()
1623
+
1624
+ try {
1625
+ binding.readlinkSync(req.handle, filepath)
1626
+
1627
+ let res = Buffer.from(binding.requestResultString(req.handle))
1628
+
1629
+ if (encoding !== 'buffer') res = res.toString(encoding)
1630
+
1631
+ return res
1632
+ } catch (e) {
1633
+ throw new FileError(e.message, {
1634
+ operation: 'readlink',
1635
+ code: e.code,
1636
+ path: filepath
1637
+ })
1638
+ } finally {
1639
+ req.return()
1640
+ }
1641
+ }
1642
+
1643
+ async function fsync(fd, cb) {
1644
+ const req = FileRequest.borrow()
1645
+
1646
+ let err = null
1647
+ try {
1648
+ binding.fsync(req.handle, fd)
1649
+
1650
+ await req
1651
+ } catch (e) {
1652
+ err = new FileError(e.message, { operation: 'fsync', code: e.code, fd })
1653
+ } finally {
1654
+ req.return()
1655
+ }
1656
+
1657
+ return done(err, cb)
1658
+ }
1659
+
1660
+ function fsyncSync(fd) {
1661
+ const req = FileRequest.borrow()
1662
+
1663
+ try {
1664
+ binding.fsyncSync(req.handle, fd)
1665
+ } catch (e) {
1666
+ throw new FileError(e.message, { operation: 'fsyncSync', code: e.code, fd })
1667
+ } finally {
1668
+ req.return()
1669
+ }
1670
+ }
1671
+
1672
+ async function fdatasync(fd, cb) {
1673
+ const req = FileRequest.borrow()
1674
+
1675
+ let err = null
1676
+ try {
1677
+ binding.fdatasync(req.handle, fd)
1678
+
1679
+ await req
1680
+ } catch (e) {
1681
+ err = new FileError(e.message, { operation: 'fdatasync', code: e.code, fd })
1682
+ } finally {
1683
+ req.return()
1684
+ }
1685
+
1686
+ return done(err, cb)
1687
+ }
1688
+
1689
+ function fdatasyncSync(fd) {
1690
+ const req = FileRequest.borrow()
1691
+
1692
+ try {
1693
+ binding.fdatasyncSync(req.handle, fd)
1694
+ } catch (e) {
1695
+ throw new FileError(e.message, { operation: 'fdatasyncSync', code: e.code, fd })
1696
+ } finally {
1697
+ req.return()
1698
+ }
1699
+ }
1700
+
1701
+ function normalizeSymlinkTarget(target, type, filepath) {
1702
+ if (isWindows) {
1703
+ if (type === constants.UV_FS_SYMLINK_JUNCTION) target = path.resolve(filepath, '..', target)
1704
+
1705
+ if (path.isAbsolute(target)) return path.toNamespacedPath(target)
1706
+
1707
+ return target.replace(/\//g, path.sep)
1708
+ }
1709
+
1710
+ return target
1711
+ }
1712
+
1713
+ async function symlink(target, filepath, type, cb) {
1714
+ if (typeof type === 'function') {
1715
+ cb = type
1716
+ type = null
1717
+ }
1718
+
1719
+ filepath = toNamespacedPath(filepath)
1720
+
1721
+ if (typeof type === 'string') {
1722
+ switch (type) {
1723
+ case 'dir':
1724
+ type = constants.UV_FS_SYMLINK_DIR
1725
+ break
1726
+ case 'junction':
1727
+ type = constants.UV_FS_SYMLINK_JUNCTION
1728
+ break
1729
+ case 'file':
1730
+ default:
1731
+ type = 0
1732
+ break
1733
+ }
1734
+ } else if (typeof type !== 'number') {
1735
+ if (isWindows) {
1736
+ target = path.resolve(filepath, '..', target)
1737
+
1738
+ try {
1739
+ type = (await stat(target)).isDirectory()
1740
+ ? constants.UV_FS_SYMLINK_DIR
1741
+ : constants.UV_FS_SYMLINK_JUNCTION
1742
+ } catch {
1743
+ type = 0
1744
+ }
1745
+ } else {
1746
+ type = 0
1747
+ }
1748
+ }
1749
+
1750
+ target = normalizeSymlinkTarget(target, type, filepath)
1751
+
1752
+ const req = FileRequest.borrow()
1753
+
1754
+ let err = null
1755
+ try {
1756
+ binding.symlink(req.handle, target, filepath, type)
1757
+
1758
+ await req
1759
+ } catch (e) {
1760
+ err = new FileError(e.message, {
1761
+ operation: 'symlink',
1762
+ code: e.code,
1763
+ path: target,
1764
+ destination: filepath
1765
+ })
1766
+ } finally {
1767
+ req.return()
1768
+ }
1769
+
1770
+ return done(err, cb)
1771
+ }
1772
+
1773
+ function symlinkSync(target, filepath, type) {
1774
+ filepath = toNamespacedPath(filepath)
1775
+
1776
+ if (typeof type === 'string') {
1777
+ switch (type) {
1778
+ case 'dir':
1779
+ type = constants.UV_FS_SYMLINK_DIR
1780
+ break
1781
+ case 'junction':
1782
+ type = constants.UV_FS_SYMLINK_JUNCTION
1783
+ break
1784
+ case 'file':
1785
+ default:
1786
+ type = 0
1787
+ break
1788
+ }
1789
+ } else if (typeof type !== 'number') {
1790
+ if (isWindows) {
1791
+ target = path.resolve(filepath, '..', target)
1792
+
1793
+ try {
1794
+ type = statSync(target).isDirectory()
1795
+ ? constants.UV_FS_SYMLINK_DIR
1796
+ : constants.UV_FS_SYMLINK_JUNCTION
1797
+ } catch {
1798
+ type = 0
1799
+ }
1800
+ } else {
1801
+ type = 0
1802
+ }
1803
+ }
1804
+
1805
+ target = normalizeSymlinkTarget(target, type, filepath)
1806
+
1807
+ const req = FileRequest.borrow()
1808
+
1809
+ try {
1810
+ binding.symlinkSync(req.handle, target, filepath, type)
1811
+ } catch (e) {
1812
+ throw new FileError(e.message, {
1813
+ operation: 'symlink',
1814
+ code: e.code,
1815
+ path: target,
1816
+ destination: filepath
1817
+ })
1818
+ } finally {
1819
+ req.return()
1820
+ }
1821
+ }
1822
+
1823
+ async function opendir(filepath, opts, cb) {
1824
+ if (typeof opts === 'function') {
1825
+ cb = opts
1826
+ opts = {}
1827
+ }
1828
+
1829
+ if (typeof opts === 'string') opts = { encoding: opts }
1830
+ else if (!opts) opts = {}
1831
+
1832
+ filepath = toNamespacedPath(filepath)
1833
+
1834
+ const req = FileRequest.borrow()
1835
+
1836
+ let dir
1837
+ let err = null
1838
+ try {
1839
+ binding.opendir(req.handle, filepath)
1840
+
1841
+ await req
1842
+
1843
+ dir = new Dir(filepath, binding.requestResultDir(req.handle), opts)
1844
+ } catch (e) {
1845
+ err = new FileError(e.message, {
1846
+ operation: 'opendir',
1847
+ code: e.code,
1848
+ path: filepath
1849
+ })
1850
+ } finally {
1851
+ req.return()
1852
+ }
1853
+
1854
+ return done(err, dir, cb)
1855
+ }
1856
+
1857
+ function opendirSync(filepath, opts) {
1858
+ if (typeof opts === 'string') opts = { encoding: opts }
1859
+ else if (!opts) opts = {}
1860
+
1861
+ filepath = toNamespacedPath(filepath)
1862
+
1863
+ const req = FileRequest.borrow()
1864
+
1865
+ try {
1866
+ binding.opendirSync(req.handle, filepath)
1867
+
1868
+ return new Dir(filepath, binding.requestResultDir(req.handle), opts)
1869
+ } catch (e) {
1870
+ throw new FileError(e.message, {
1871
+ operation: 'opendir',
1872
+ code: e.code,
1873
+ path: filepath
1874
+ })
1875
+ } finally {
1876
+ req.return()
1877
+ }
1878
+ }
1879
+
1880
+ async function readdir(filepath, opts, cb) {
1881
+ if (typeof opts === 'function') {
1882
+ cb = opts
1883
+ opts = {}
1884
+ }
1885
+
1886
+ if (typeof opts === 'string') opts = { encoding: opts }
1887
+ else if (!opts) opts = {}
1888
+
1889
+ const { withFileTypes = false, recursive = false } = opts
1890
+
1891
+ filepath = toNamespacedPath(filepath)
1892
+
1893
+ const queue = [filepath]
1894
+ let result = []
1895
+ let err = null
1896
+ try {
1897
+ while (queue.length !== 0) {
1898
+ const dir = await opendir(queue.pop())
1899
+
1900
+ for await (const entry of dir) {
1901
+ const entryPath = path.join(entry.parentPath, entry.name)
1902
+
1903
+ if (withFileTypes) {
1904
+ result.push(entry)
1905
+ } else {
1906
+ result.push(path.relative(filepath, entryPath))
1907
+ }
1908
+
1909
+ if (recursive && entry.isDirectory()) queue.push(entryPath)
1910
+ }
1911
+ }
1912
+ } catch (e) {
1913
+ result = []
1914
+ err = e
1915
+ }
1916
+
1917
+ return done(err, result, cb)
1918
+ }
1919
+
1920
+ function readdirSync(filepath, opts) {
1921
+ if (typeof opts === 'string') opts = { encoding: opts }
1922
+ else if (!opts) opts = {}
1923
+
1924
+ const { withFileTypes = false, recursive = false } = opts
1925
+
1926
+ filepath = toNamespacedPath(filepath)
1927
+
1928
+ const queue = [filepath]
1929
+ const result = []
1930
+
1931
+ while (queue.length !== 0) {
1932
+ const dir = opendirSync(queue.pop(), opts)
1933
+
1934
+ for (const entry of dir) {
1935
+ const entryPath = path.join(entry.parentPath, entry.name)
1936
+
1937
+ if (withFileTypes) {
1938
+ result.push(entry)
1939
+ } else {
1940
+ result.push(path.relative(filepath, entryPath))
1941
+ }
1942
+
1943
+ if (recursive && entry.isDirectory()) queue.push(entryPath)
1944
+ }
1945
+ }
1946
+
1947
+ return result
1948
+ }
1949
+
1950
+ async function readFile(filepath, opts, cb) {
1951
+ if (typeof opts === 'function') {
1952
+ cb = opts
1953
+ opts = {}
1954
+ }
1955
+
1956
+ if (typeof opts === 'string') opts = { encoding: opts }
1957
+ else if (!opts) opts = {}
1958
+
1959
+ const { encoding = 'buffer' } = opts
1960
+
1961
+ let fd = -1
1962
+ let buffer = null
1963
+ let err = null
1964
+ try {
1965
+ fd = await open(filepath, opts.flag || 'r')
1966
+
1967
+ const st = await fstat(fd)
1968
+
1969
+ let len = 0
1970
+
1971
+ if (st.size === 0) {
1972
+ const buffers = []
1973
+
1974
+ while (true) {
1975
+ buffer = Buffer.allocUnsafe(8192)
1976
+ const r = await read(fd, buffer)
1977
+ len += r
1978
+ if (r === 0) break
1979
+ buffers.push(buffer.subarray(0, r))
1980
+ }
1981
+
1982
+ buffer = Buffer.concat(buffers)
1983
+ } else {
1984
+ buffer = Buffer.allocUnsafe(st.size)
1985
+
1986
+ while (true) {
1987
+ const r = await read(fd, len ? buffer.subarray(len) : buffer)
1988
+ len += r
1989
+ if (r === 0 || len === buffer.byteLength) break
1990
+ }
1991
+
1992
+ if (len !== buffer.byteLength) buffer = buffer.subarray(0, len)
1993
+ }
1994
+
1995
+ if (encoding !== 'buffer') buffer = buffer.toString(encoding)
1996
+ } catch (e) {
1997
+ err = e
1998
+ } finally {
1999
+ if (fd !== -1) await close(fd)
2000
+ }
2001
+
2002
+ return done(err, buffer, cb)
2003
+ }
2004
+
2005
+ function readFileSync(filepath, opts) {
2006
+ if (typeof opts === 'string') opts = { encoding: opts }
2007
+ else if (!opts) opts = {}
2008
+
2009
+ const { encoding = 'buffer' } = opts
2010
+
2011
+ let fd = -1
2012
+ try {
2013
+ fd = openSync(filepath, opts.flag || 'r')
2014
+
2015
+ const st = fstatSync(fd)
2016
+
2017
+ let buffer
2018
+ let len = 0
2019
+
2020
+ if (st.size === 0) {
2021
+ const buffers = []
2022
+
2023
+ while (true) {
2024
+ buffer = Buffer.allocUnsafe(8192)
2025
+ const r = readSync(fd, buffer)
2026
+ len += r
2027
+ if (r === 0) break
2028
+ buffers.push(buffer.subarray(0, r))
2029
+ }
2030
+
2031
+ buffer = Buffer.concat(buffers)
2032
+ } else {
2033
+ buffer = Buffer.allocUnsafe(st.size)
2034
+
2035
+ while (true) {
2036
+ const r = readSync(fd, len ? buffer.subarray(len) : buffer)
2037
+ len += r
2038
+ if (r === 0 || len === buffer.byteLength) break
2039
+ }
2040
+
2041
+ if (len !== buffer.byteLength) buffer = buffer.subarray(0, len)
2042
+ }
2043
+
2044
+ if (encoding !== 'buffer') buffer = buffer.toString(encoding)
2045
+
2046
+ return buffer
2047
+ } finally {
2048
+ if (fd !== -1) closeSync(fd)
2049
+ }
2050
+ }
2051
+
2052
+ async function writeFile(filepath, data, opts, cb) {
2053
+ if (typeof opts === 'function') {
2054
+ cb = opts
2055
+ opts = {}
2056
+ }
2057
+
2058
+ if (typeof opts === 'string') opts = { encoding: opts }
2059
+ else if (!opts) opts = {}
2060
+
2061
+ if (typeof data === 'string') data = Buffer.from(data, opts.encoding)
2062
+
2063
+ let fd = -1
2064
+ let len = 0
2065
+ let err = null
2066
+ try {
2067
+ fd = await open(filepath, opts.flag || 'w', opts.mode || 0o666)
2068
+
2069
+ while (true) {
2070
+ len += await write(fd, len ? data.subarray(len) : data)
2071
+ if (len === data.byteLength) break
2072
+ }
2073
+ } catch (e) {
2074
+ err = e
2075
+ } finally {
2076
+ if (fd !== -1) await close(fd)
2077
+ }
2078
+
2079
+ return done(err, len, cb)
2080
+ }
2081
+
2082
+ function writeFileSync(filepath, data, opts) {
2083
+ if (typeof opts === 'string') opts = { encoding: opts }
2084
+ else if (!opts) opts = {}
2085
+
2086
+ if (typeof data === 'string') data = Buffer.from(data, opts.encoding)
2087
+
2088
+ let fd = -1
2089
+ try {
2090
+ fd = openSync(filepath, opts.flag || 'w', opts.mode || 0o666)
2091
+
2092
+ let len = 0
2093
+
2094
+ while (true) {
2095
+ len += writeSync(fd, len ? data.subarray(len) : data)
2096
+ if (len === data.byteLength) break
2097
+ }
2098
+ } finally {
2099
+ if (fd !== -1) closeSync(fd)
2100
+ }
2101
+ }
2102
+
2103
+ function appendFile(filepath, data, opts, cb) {
2104
+ if (typeof opts === 'function') {
2105
+ cb = opts
2106
+ opts = {}
2107
+ }
2108
+
2109
+ if (typeof opts === 'string') opts = { encoding: opts }
2110
+ else if (!opts) opts = {}
2111
+
2112
+ if (!opts.flag) opts = { ...opts, flag: 'a' }
2113
+
2114
+ return writeFile(filepath, data, opts, cb)
2115
+ }
2116
+
2117
+ function appendFileSync(filepath, data, opts) {
2118
+ if (typeof opts === 'string') opts = { encoding: opts }
2119
+ else if (!opts) opts = {}
2120
+
2121
+ if (!opts.flag) opts = { ...opts, flag: 'a' }
2122
+
2123
+ return writeFileSync(filepath, data, opts)
2124
+ }
2125
+
2126
+ function watch(filepath, opts, cb) {
2127
+ if (typeof opts === 'function') {
2128
+ cb = opts
2129
+ opts = {}
2130
+ }
2131
+
2132
+ if (typeof opts === 'string') opts = { encoding: opts }
2133
+ else if (!opts) opts = {}
2134
+
2135
+ filepath = toNamespacedPath(filepath)
2136
+
2137
+ return new Watcher(filepath, opts, cb)
2138
+ }
2139
+
2140
+ class Stats {
2141
+ constructor(
2142
+ dev,
2143
+ mode,
2144
+ nlink,
2145
+ uid,
2146
+ gid,
2147
+ rdev,
2148
+ blksize,
2149
+ ino,
2150
+ size,
2151
+ blocks,
2152
+ atimeMs,
2153
+ mtimeMs,
2154
+ ctimeMs,
2155
+ birthtimeMs
2156
+ ) {
2157
+ this.dev = dev
2158
+ this.mode = mode
2159
+ this.nlink = nlink
2160
+ this.uid = uid
2161
+ this.gid = gid
2162
+ this.rdev = rdev
2163
+ this.blksize = blksize
2164
+ this.ino = ino
2165
+ this.size = size
2166
+ this.blocks = blocks
2167
+ this.atimeMs = atimeMs
2168
+ this.mtimeMs = mtimeMs
2169
+ this.ctimeMs = ctimeMs
2170
+ this.birthtimeMs = birthtimeMs
2171
+ this.atime = new Date(atimeMs)
2172
+ this.mtime = new Date(mtimeMs)
2173
+ this.ctime = new Date(ctimeMs)
2174
+ this.birthtime = new Date(birthtimeMs)
2175
+ }
2176
+
2177
+ isDirectory() {
2178
+ return (this.mode & constants.S_IFMT) === constants.S_IFDIR
2179
+ }
2180
+
2181
+ isFile() {
2182
+ return (this.mode & constants.S_IFMT) === constants.S_IFREG
2183
+ }
2184
+
2185
+ isBlockDevice() {
2186
+ return (this.mode & constants.S_IFMT) === constants.S_IFBLK
2187
+ }
2188
+
2189
+ isCharacterDevice() {
2190
+ return (this.mode & constants.S_IFMT) === constants.S_IFCHR
2191
+ }
2192
+
2193
+ isFIFO() {
2194
+ return (this.mode & constants.S_IFMT) === constants.S_IFIFO
2195
+ }
2196
+
2197
+ isSymbolicLink() {
2198
+ return (this.mode & constants.S_IFMT) === constants.S_IFLNK
2199
+ }
2200
+
2201
+ isSocket() {
2202
+ return (this.mode & constants.S_IFMT) === constants.S_IFSOCK
2203
+ }
2204
+ }
2205
+
2206
+ class StatFs {
2207
+ constructor(type, bsize, blocks, bfree, bavail, files, ffree) {
2208
+ this.type = type
2209
+ this.bsize = bsize
2210
+ this.blocks = blocks
2211
+ this.bfree = bfree
2212
+ this.bavail = bavail
2213
+ this.files = files
2214
+ this.ffree = ffree
2215
+ }
2216
+ }
2217
+
2218
+ class Dir {
2219
+ constructor(path, handle, opts = {}) {
2220
+ const { encoding = 'utf8', bufferSize = 32 } = opts
2221
+
2222
+ this.path = path
2223
+
2224
+ this._encoding = encoding
2225
+ this._capacity = bufferSize
2226
+ this._buffer = new FIFO()
2227
+ this._ended = false
2228
+ this._handle = handle
2229
+ }
2230
+
2231
+ async read(cb) {
2232
+ if (this._buffer.length) return ok(this._buffer.shift(), cb)
2233
+ if (this._ended) return ok(null, cb)
2234
+
2235
+ const req = FileRequest.borrow()
2236
+
2237
+ let entries
2238
+ let err = null
2239
+ try {
2240
+ req.retain(binding.readdir(req.handle, this._handle, this._capacity))
2241
+
2242
+ await req
2243
+
2244
+ entries = binding.requestResultDirents(req.handle)
2245
+ } catch (e) {
2246
+ err = new FileError(e.message, {
2247
+ operation: 'readdir',
2248
+ code: e.code,
2249
+ path: this.path
2250
+ })
2251
+ } finally {
2252
+ req.return()
2253
+ }
2254
+
2255
+ if (err) return fail(err, cb)
2256
+
2257
+ if (entries.length === 0) {
2258
+ this._ended = true
2259
+
2260
+ return ok(null, cb)
2261
+ }
2262
+
2263
+ for (const entry of entries) {
2264
+ let name = Buffer.from(entry.name)
2265
+
2266
+ if (this._encoding !== 'buffer') name = name.toString(this._encoding)
2267
+
2268
+ this._buffer.push(new Dirent(this.path, name, entry.type))
2269
+ }
2270
+
2271
+ return ok(this._buffer.shift(), cb)
2272
+ }
2273
+
2274
+ readSync() {
2275
+ if (this._buffer.length) return this._buffer.shift()
2276
+ if (this._ended) return null
2277
+
2278
+ const req = FileRequest.borrow()
2279
+
2280
+ let entries
2281
+ try {
2282
+ req.retain(binding.readdirSync(req.handle, this._handle, this._capacity))
2283
+
2284
+ entries = binding.requestResultDirents(req.handle)
2285
+ } catch (e) {
2286
+ throw new FileError(e.message, {
2287
+ operation: 'readdir',
2288
+ code: e.code,
2289
+ path: this.path
2290
+ })
2291
+ } finally {
2292
+ req.return()
2293
+ }
2294
+
2295
+ if (entries.length === 0) {
2296
+ this._ended = true
2297
+
2298
+ return null
2299
+ }
2300
+
2301
+ for (const entry of entries) {
2302
+ let name = Buffer.from(entry.name)
2303
+
2304
+ if (this._encoding !== 'buffer') name = name.toString(this._encoding)
2305
+
2306
+ this._buffer.push(new Dirent(this.path, name, entry.type))
2307
+ }
2308
+
2309
+ return this._buffer.shift()
2310
+ }
2311
+
2312
+ async close(cb) {
2313
+ const req = FileRequest.borrow()
2314
+
2315
+ let err = null
2316
+ try {
2317
+ binding.closedir(req.handle, this._handle)
2318
+
2319
+ await req
2320
+ } catch (e) {
2321
+ err = new FileError(e.message, {
2322
+ operation: 'closedir',
2323
+ code: e.code,
2324
+ path: this.path
2325
+ })
2326
+ } finally {
2327
+ req.return()
2328
+ }
2329
+
2330
+ this._handle = null
2331
+
2332
+ return done(err, cb)
2333
+ }
2334
+
2335
+ closeSync() {
2336
+ const req = FileRequest.borrow()
2337
+
2338
+ try {
2339
+ binding.closedirSync(req.handle, this._handle)
2340
+ } catch (e) {
2341
+ throw new FileError(e.message, {
2342
+ operation: 'closedir',
2343
+ code: e.code,
2344
+ path: this.path
2345
+ })
2346
+ } finally {
2347
+ req.return()
2348
+ }
2349
+
2350
+ this._handle = null
2351
+ }
2352
+
2353
+ [Symbol.dispose]() {
2354
+ this.closeSync()
2355
+ }
2356
+
2357
+ async [Symbol.asyncDispose]() {
2358
+ await this.close()
2359
+ }
2360
+
2361
+ *[Symbol.iterator]() {
2362
+ while (true) {
2363
+ const entry = this.readSync()
2364
+ if (entry === null) break
2365
+ yield entry
2366
+ }
2367
+
2368
+ this.closeSync()
2369
+ }
2370
+
2371
+ async *[Symbol.asyncIterator]() {
2372
+ while (true) {
2373
+ const entry = await this.read()
2374
+ if (entry === null) break
2375
+ yield entry
2376
+ }
2377
+
2378
+ await this.close()
2379
+ }
2380
+ }
2381
+
2382
+ class Dirent {
2383
+ constructor(parentPath, name, type) {
2384
+ this.parentPath = parentPath
2385
+ this.name = name
2386
+ this.type = type
2387
+ }
2388
+
2389
+ isFile() {
2390
+ return this.type === constants.UV_DIRENT_FILE
2391
+ }
2392
+
2393
+ isDirectory() {
2394
+ return this.type === constants.UV_DIRENT_DIR
2395
+ }
2396
+
2397
+ isSymbolicLink() {
2398
+ return this.type === constants.UV_DIRENT_LINK
2399
+ }
2400
+
2401
+ isFIFO() {
2402
+ return this.type === constants.UV_DIRENT_FIFO
2403
+ }
2404
+
2405
+ isSocket() {
2406
+ return this.type === constants.UV_DIRENT_SOCKET
2407
+ }
2408
+
2409
+ isCharacterDevice() {
2410
+ return this.type === constants.UV_DIRENT_CHAR
2411
+ }
2412
+
2413
+ isBlockDevice() {
2414
+ return this.type === constants.UV_DIRENT_BLOCK
2415
+ }
2416
+ }
2417
+
2418
+ class FileReadStream extends Readable {
2419
+ constructor(path, opts = {}) {
2420
+ const { eagerOpen = true } = opts
2421
+
2422
+ super({ eagerOpen, ...opts })
2423
+
2424
+ this.path = path
2425
+ this.fd = typeof opts.fd === 'number' ? opts.fd : -1
2426
+ this.flags = opts.flags || 'r'
2427
+ this.mode = opts.mode || 0o666
2428
+
2429
+ this._offset = opts.start || 0
2430
+ this._missing = 0
2431
+
2432
+ if (opts.length) {
2433
+ this._missing = opts.length
2434
+ } else if (typeof opts.end === 'number') {
2435
+ this._missing = opts.end - this._offset + 1
2436
+ } else {
2437
+ this._missing = -1
2438
+ }
2439
+ }
2440
+
2441
+ async _open(cb) {
2442
+ let err
2443
+
2444
+ if (this.fd === -1) {
2445
+ err = null
2446
+ try {
2447
+ this.fd = await open(this.path, this.flags, this.mode)
2448
+ } catch (e) {
2449
+ err = e
2450
+ }
2451
+
2452
+ if (err) return cb(err)
2453
+ }
2454
+
2455
+ let st
2456
+ err = null
2457
+ try {
2458
+ st = await fstat(this.fd)
2459
+ } catch (e) {
2460
+ err = e
2461
+ }
2462
+
2463
+ if (err) return cb(err)
2464
+
2465
+ if (this._missing === -1) this._missing = st.size
2466
+
2467
+ if (st.size < this._offset) {
2468
+ this._offset = st.size
2469
+ this._missing = 0
2470
+ } else if (st.size < this._offset + this._missing) {
2471
+ this._missing = st.size - this._offset
2472
+ }
2473
+
2474
+ cb(null)
2475
+ }
2476
+
2477
+ async _read(size) {
2478
+ if (this._missing <= 0) return this.push(null)
2479
+
2480
+ const data = Buffer.allocUnsafe(Math.min(this._missing, size))
2481
+
2482
+ let len
2483
+ let err = null
2484
+ try {
2485
+ len = await read(this.fd, data, 0, data.byteLength, this._offset)
2486
+ } catch (e) {
2487
+ err = e
2488
+ }
2489
+
2490
+ if (err) return this.destroy(err)
2491
+
2492
+ if (len === 0) return this.push(null)
2493
+
2494
+ if (this._missing < len) len = this._missing
2495
+
2496
+ this._missing -= len
2497
+ this._offset += len
2498
+
2499
+ this.push(data.subarray(0, len))
2500
+ }
2501
+
2502
+ async _destroy(err, cb) {
2503
+ if (this.fd === -1) return cb(err)
2504
+
2505
+ try {
2506
+ await close(this.fd)
2507
+ } catch (e) {
2508
+ err = err || e
2509
+ }
2510
+
2511
+ cb(err)
2512
+ }
2513
+ }
2514
+
2515
+ class FileWriteStream extends Writable {
2516
+ constructor(path, opts = {}) {
2517
+ const { eagerOpen = true } = opts
2518
+
2519
+ super({ eagerOpen, ...opts })
2520
+
2521
+ this.path = path
2522
+ this.fd = typeof opts.fd === 'number' ? opts.fd : -1
2523
+ this.flags = opts.flags || 'w'
2524
+ this.mode = opts.mode || 0o666
2525
+ }
2526
+
2527
+ async _open(cb) {
2528
+ if (this.fd !== -1) return cb(null)
2529
+
2530
+ let err = null
2531
+ try {
2532
+ this.fd = await open(this.path, this.flags, this.mode)
2533
+ } catch (e) {
2534
+ err = e
2535
+ }
2536
+
2537
+ cb(err)
2538
+ }
2539
+
2540
+ async _writev(batch, cb) {
2541
+ let err = null
2542
+ try {
2543
+ await writev(
2544
+ this.fd,
2545
+ batch.map(({ chunk }) => chunk)
2546
+ )
2547
+ } catch (e) {
2548
+ err = e
2549
+ }
2550
+
2551
+ cb(err)
2552
+ }
2553
+
2554
+ async _destroy(err, cb) {
2555
+ if (this.fd === -1) return cb(err)
2556
+
2557
+ try {
2558
+ await close(this.fd)
2559
+ } catch (e) {
2560
+ err = err || e
2561
+ }
2562
+
2563
+ cb(err)
2564
+ }
2565
+ }
2566
+
2567
+ class Watcher extends EventEmitter {
2568
+ constructor(path, opts, onchange) {
2569
+ if (typeof opts === 'function') {
2570
+ onchange = opts
2571
+ opts = {}
2572
+ }
2573
+
2574
+ if (!opts) opts = {}
2575
+
2576
+ const { persistent = true, recursive = false, encoding = 'utf8' } = opts
2577
+
2578
+ super()
2579
+
2580
+ this._closed = false
2581
+ this._encoding = encoding
2582
+ this._handle = binding.watcherInit(path, recursive, this, this._onevent, this._onclose)
2583
+
2584
+ if (!persistent) this.unref()
2585
+
2586
+ if (onchange) this.on('change', onchange)
2587
+ }
2588
+
2589
+ close() {
2590
+ if (this._closed) return
2591
+ this._closed = true
2592
+
2593
+ binding.watcherClose(this._handle)
2594
+ }
2595
+
2596
+ ref() {
2597
+ if (this._handle) binding.watcherRef(this._handle)
2598
+ return this
2599
+ }
2600
+
2601
+ unref() {
2602
+ if (this._handle) binding.watcherUnref(this._handle)
2603
+ return this
2604
+ }
2605
+
2606
+ [Symbol.asyncIterator]() {
2607
+ const buffer = []
2608
+ let done = false
2609
+ let error = null
2610
+ let next = null
2611
+
2612
+ this.on('change', (eventType, filename) => {
2613
+ if (next) {
2614
+ next.resolve({ done: false, value: { eventType, filename } })
2615
+ next = null
2616
+ } else {
2617
+ buffer.push({ eventType, filename })
2618
+ }
2619
+ })
2620
+ .on('error', (err) => {
2621
+ done = true
2622
+ error = err
2623
+
2624
+ if (next) {
2625
+ next.reject(error)
2626
+ next = null
2627
+ }
2628
+ })
2629
+ .on('close', () => {
2630
+ done = true
2631
+
2632
+ if (next) {
2633
+ next.resolve({ done })
2634
+ next = null
2635
+ }
2636
+ })
2637
+
2638
+ return {
2639
+ next: () =>
2640
+ new Promise((resolve, reject) => {
2641
+ if (error) return reject(error)
2642
+
2643
+ if (buffer.length) return resolve({ done: false, value: buffer.shift() })
2644
+
2645
+ if (done) return resolve({ done })
2646
+
2647
+ next = { resolve, reject }
2648
+ })
2649
+ }
2650
+ }
2651
+
2652
+ _onevent(err, events, filename) {
2653
+ if (err) {
2654
+ this.close()
2655
+ this.emit('error', err)
2656
+ } else {
2657
+ const path =
2658
+ this._encoding === 'buffer'
2659
+ ? Buffer.from(filename)
2660
+ : Buffer.from(filename).toString(this._encoding)
2661
+
2662
+ if (events & binding.UV_RENAME) {
2663
+ this.emit('change', 'rename', path)
2664
+ }
2665
+
2666
+ if (events & binding.UV_CHANGE) {
2667
+ this.emit('change', 'change', path)
2668
+ }
2669
+ }
2670
+ }
2671
+
2672
+ _onclose() {
2673
+ this._handle = null
2674
+
2675
+ this.emit('close')
2676
+ }
2677
+ }
2678
+
2679
+ exports.access = access
2680
+ exports.appendFile = appendFile
2681
+ exports.chmod = chmod
2682
+ exports.chown = chown
2683
+ exports.close = close
2684
+ exports.copyFile = copyFile
2685
+ exports.cp = cp
2686
+ exports.exists = exists
2687
+ exports.fchmod = fchmod
2688
+ exports.fchown = fchown
2689
+ exports.fdatasync = fdatasync
2690
+ exports.fstat = fstat
2691
+ exports.fsync = fsync
2692
+ exports.ftruncate = ftruncate
2693
+ exports.futimes = futimes
2694
+ exports.lchown = lchown
2695
+ exports.lutimes = lutimes
2696
+ exports.link = link
2697
+ exports.lstat = lstat
2698
+ exports.mkdir = mkdir
2699
+ exports.mkdtemp = mkdtemp
2700
+ exports.open = open
2701
+ exports.opendir = opendir
2702
+ exports.read = read
2703
+ exports.readFile = readFile
2704
+ exports.readdir = readdir
2705
+ exports.readlink = readlink
2706
+ exports.readv = readv
2707
+ exports.realpath = realpath
2708
+ exports.rename = rename
2709
+ exports.rm = rm
2710
+ exports.rmdir = rmdir
2711
+ exports.stat = stat
2712
+ exports.statfs = statfs
2713
+ exports.symlink = symlink
2714
+ exports.truncate = truncate
2715
+ exports.unlink = unlink
2716
+ exports.utimes = utimes
2717
+ exports.watch = watch
2718
+ exports.write = write
2719
+ exports.writeFile = writeFile
2720
+ exports.writev = writev
2721
+
2722
+ exports.accessSync = accessSync
2723
+ exports.appendFileSync = appendFileSync
2724
+ exports.chmodSync = chmodSync
2725
+ exports.chownSync = chownSync
2726
+ exports.closeSync = closeSync
2727
+ exports.copyFileSync = copyFileSync
2728
+ exports.cpSync = cpSync
2729
+ exports.existsSync = existsSync
2730
+ exports.fchmodSync = fchmodSync
2731
+ exports.fchownSync = fchownSync
2732
+ exports.fdatasyncSync = fdatasyncSync
2733
+ exports.fstatSync = fstatSync
2734
+ exports.fsyncSync = fsyncSync
2735
+ exports.ftruncateSync = ftruncateSync
2736
+ exports.futimesSync = futimesSync
2737
+ exports.lchownSync = lchownSync
2738
+ exports.lutimesSync = lutimesSync
2739
+ exports.linkSync = linkSync
2740
+ exports.lstatSync = lstatSync
2741
+ exports.mkdirSync = mkdirSync
2742
+ exports.mkdtempSync = mkdtempSync
2743
+ exports.openSync = openSync
2744
+ exports.opendirSync = opendirSync
2745
+ exports.readFileSync = readFileSync
2746
+ exports.readSync = readSync
2747
+ exports.readdirSync = readdirSync
2748
+ exports.readlinkSync = readlinkSync
2749
+ exports.readvSync = readvSync
2750
+ exports.realpathSync = realpathSync
2751
+ exports.renameSync = renameSync
2752
+ exports.rmSync = rmSync
2753
+ exports.rmdirSync = rmdirSync
2754
+ exports.statSync = statSync
2755
+ exports.statfsSync = statfsSync
2756
+ exports.symlinkSync = symlinkSync
2757
+ exports.truncateSync = truncateSync
2758
+ exports.unlinkSync = unlinkSync
2759
+ exports.utimesSync = utimesSync
2760
+ exports.writeFileSync = writeFileSync
2761
+ exports.writeSync = writeSync
2762
+ exports.writevSync = writevSync
2763
+
2764
+ exports.promises = require('./promises')
2765
+
2766
+ exports.Stats = Stats
2767
+ exports.StatFs = StatFs
2768
+ exports.Dir = Dir
2769
+ exports.Dirent = Dirent
2770
+ exports.Watcher = Watcher
2771
+
2772
+ exports.ReadStream = FileReadStream
2773
+
2774
+ exports.createReadStream = function createReadStream(path, opts) {
2775
+ return new FileReadStream(path, opts)
2776
+ }
2777
+
2778
+ exports.WriteStream = FileWriteStream
2779
+
2780
+ exports.createWriteStream = function createWriteStream(path, opts) {
2781
+ return new FileWriteStream(path, opts)
2782
+ }
2783
+
2784
+ function toNamespacedPath(filepath) {
2785
+ if (typeof filepath !== 'string') {
2786
+ if (isURL(filepath)) filepath = fileURLToPath(filepath)
2787
+ else filepath = filepath.toString()
2788
+ }
2789
+
2790
+ return path.toNamespacedPath(filepath)
2791
+ }
2792
+
2793
+ function toFlags(flags) {
2794
+ switch (flags) {
2795
+ case 'r':
2796
+ return constants.O_RDONLY
2797
+ case 'rs': // Fall through.
2798
+ case 'sr':
2799
+ return constants.O_RDONLY | constants.O_SYNC
2800
+ case 'r+':
2801
+ return constants.O_RDWR
2802
+ case 'rs+': // Fall through.
2803
+ case 'sr+':
2804
+ return constants.O_RDWR | constants.O_SYNC
2805
+
2806
+ case 'w':
2807
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY
2808
+ case 'wx': // Fall through.
2809
+ case 'xw':
2810
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL
2811
+
2812
+ case 'w+':
2813
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR
2814
+ case 'wx+': // Fall through.
2815
+ case 'xw+':
2816
+ return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL
2817
+
2818
+ case 'a':
2819
+ return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY
2820
+ case 'ax': // Fall through.
2821
+ case 'xa':
2822
+ return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL
2823
+ case 'as': // Fall through.
2824
+ case 'sa':
2825
+ return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_SYNC
2826
+
2827
+ case 'a+':
2828
+ return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR
2829
+ case 'ax+': // Fall through.
2830
+ case 'xa+':
2831
+ return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL
2832
+ case 'as+': // Fall through.
2833
+ case 'sa+':
2834
+ return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_SYNC
2835
+ default:
2836
+ return 0
2837
+ }
2838
+ }
2839
+
2840
+ function toMode(mode) {
2841
+ return parseInt(mode, 8)
2842
+ }
node_modules/bare-fs/lib/constants.d.ts ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare const constants: {
2
+ O_RDWR: number
3
+ O_RDONLY: number
4
+ O_WRONLY: number
5
+ O_CREAT: number
6
+ O_TRUNC: number
7
+ O_APPEND: number
8
+
9
+ F_OK: number
10
+ R_OK: number
11
+ W_OK: number
12
+ X_OK: number
13
+
14
+ S_IFMT: number
15
+ S_IFREG: number
16
+ S_IFDIR: number
17
+ S_IFCHR: number
18
+ S_IFLNK: number
19
+ S_IFBLK: number
20
+ S_IFIFO: number
21
+ S_IFSOCK: number
22
+
23
+ S_IRUSR: number
24
+ S_IWUSR: number
25
+ S_IXUSR: number
26
+ S_IRGRP: number
27
+ S_IWGRP: number
28
+ S_IXGRP: number
29
+ S_IROTH: number
30
+ S_IWOTH: number
31
+ S_IXOTH: number
32
+
33
+ UV_DIRENT_UNKNOWN: number
34
+ UV_DIRENT_FILE: number
35
+ UV_DIRENT_DIR: number
36
+ UV_DIRENT_LINK: number
37
+ UV_DIRENT_FIFO: number
38
+ UV_DIRENT_SOCKET: number
39
+ UV_DIRENT_CHAR: number
40
+ UV_DIRENT_BLOCK: number
41
+
42
+ COPYFILE_EXCL: number
43
+ COPYFILE_FICLONE: number
44
+ COPYFILE_FICLONE_FORCE: number
45
+ UV_FS_SYMLINK_DIR: number
46
+ UV_FS_SYMLINK_JUNCTION: number
47
+ }
48
+
49
+ export = constants
node_modules/bare-fs/lib/constants.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const binding = require('../binding')
2
+
3
+ module.exports = {
4
+ O_RDWR: binding.O_RDWR,
5
+ O_RDONLY: binding.O_RDONLY,
6
+ O_WRONLY: binding.O_WRONLY,
7
+ O_CREAT: binding.O_CREAT,
8
+ O_TRUNC: binding.O_TRUNC,
9
+ O_APPEND: binding.O_APPEND,
10
+
11
+ F_OK: binding.F_OK || 0,
12
+ R_OK: binding.R_OK || 0,
13
+ W_OK: binding.W_OK || 0,
14
+ X_OK: binding.X_OK || 0,
15
+
16
+ S_IFMT: binding.S_IFMT,
17
+ S_IFREG: binding.S_IFREG,
18
+ S_IFDIR: binding.S_IFDIR,
19
+ S_IFCHR: binding.S_IFCHR,
20
+ S_IFLNK: binding.S_IFLNK,
21
+ S_IFBLK: binding.S_IFBLK || 0,
22
+ S_IFIFO: binding.S_IFIFO || 0,
23
+ S_IFSOCK: binding.S_IFSOCK || 0,
24
+
25
+ S_IRUSR: binding.S_IRUSR || 0,
26
+ S_IWUSR: binding.S_IWUSR || 0,
27
+ S_IXUSR: binding.S_IXUSR || 0,
28
+ S_IRGRP: binding.S_IRGRP || 0,
29
+ S_IWGRP: binding.S_IWGRP || 0,
30
+ S_IXGRP: binding.S_IXGRP || 0,
31
+ S_IROTH: binding.S_IROTH || 0,
32
+ S_IWOTH: binding.S_IWOTH || 0,
33
+ S_IXOTH: binding.S_IXOTH || 0,
34
+
35
+ UV_DIRENT_UNKNOWN: binding.UV_DIRENT_UNKNOWN,
36
+ UV_DIRENT_FILE: binding.UV_DIRENT_FILE,
37
+ UV_DIRENT_DIR: binding.UV_DIRENT_DIR,
38
+ UV_DIRENT_LINK: binding.UV_DIRENT_LINK,
39
+ UV_DIRENT_FIFO: binding.UV_DIRENT_FIFO,
40
+ UV_DIRENT_SOCKET: binding.UV_DIRENT_SOCKET,
41
+ UV_DIRENT_CHAR: binding.UV_DIRENT_CHAR,
42
+ UV_DIRENT_BLOCK: binding.UV_DIRENT_BLOCK,
43
+
44
+ COPYFILE_EXCL: binding.UV_FS_COPYFILE_EXCL,
45
+ COPYFILE_FICLONE: binding.UV_FS_COPYFILE_FICLONE,
46
+ COPYFILE_FICLONE_FORCE: binding.UV_FS_COPYFILE_FICLONE_FORCE,
47
+ UV_FS_SYMLINK_DIR: binding.UV_FS_SYMLINK_DIR,
48
+ UV_FS_SYMLINK_JUNCTION: binding.UV_FS_SYMLINK_JUNCTION
49
+ }
node_modules/bare-fs/lib/errors.d.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare class FileError extends Error {
2
+ private constructor(msg: string)
3
+
4
+ readonly code: string
5
+ readonly operation?: string
6
+ readonly path?: string
7
+ readonly destination?: string
8
+ readonly fd?: number
9
+ }
10
+
11
+ export = FileError
node_modules/bare-fs/lib/errors.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const os = require('bare-os')
2
+
3
+ module.exports = class FileError extends Error {
4
+ constructor(msg, opts = {}) {
5
+ const { code, operation = null, path = null, destination = null, fd = -1 } = opts
6
+
7
+ if (operation !== null) msg += describe(operation, opts)
8
+
9
+ super(`${code}: ${msg}`)
10
+
11
+ this.code = code
12
+
13
+ if (operation !== null) this.operation = operation
14
+ if (path !== null) this.path = path
15
+ if (destination !== null) this.destination = destination
16
+ if (fd !== -1) this.fd = fd
17
+ }
18
+
19
+ get name() {
20
+ return 'FileError'
21
+ }
22
+
23
+ // For Node.js compatibility
24
+ get errno() {
25
+ return os.constants.errnos[this.code]
26
+ }
27
+
28
+ // For Node.js compatibility
29
+ get syscall() {
30
+ return this.operation
31
+ }
32
+
33
+ // For Node.js compatibility
34
+ get dest() {
35
+ return this.destination
36
+ }
37
+ }
38
+
39
+ function describe(operation, opts) {
40
+ const { path = null, destination = null, fd = -1 } = opts
41
+
42
+ let result = `, ${operation}`
43
+
44
+ if (path !== null) {
45
+ result += ` ${JSON.stringify(path)}`
46
+
47
+ if (destination !== null) {
48
+ result += ` -> ${JSON.stringify(destination)}`
49
+ }
50
+ } else if (fd !== -1) {
51
+ result += ` ${fd}`
52
+ }
53
+
54
+ return result
55
+ }
node_modules/bare-fs/package.json ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "bare-fs",
3
+ "version": "4.7.2",
4
+ "description": "Native file system operations for Bare",
5
+ "exports": {
6
+ "./package": "./package.json",
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ },
11
+ "./promises": {
12
+ "types": "./promises.d.ts",
13
+ "default": "./promises.js"
14
+ },
15
+ "./constants": {
16
+ "types": "./lib/constants.d.ts",
17
+ "default": "./lib/constants.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "index.js",
22
+ "index.d.ts",
23
+ "promises.js",
24
+ "promises.d.ts",
25
+ "binding.c",
26
+ "binding.js",
27
+ "CMakeLists.txt",
28
+ "lib",
29
+ "prebuilds"
30
+ ],
31
+ "addon": true,
32
+ "scripts": {
33
+ "format": "prettier --write . && lunte --fix",
34
+ "lint": "prettier --check . && lunte",
35
+ "test": "brittle-bare --coverage test.js"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/holepunchto/bare-fs.git"
40
+ },
41
+ "author": "Holepunch",
42
+ "license": "Apache-2.0",
43
+ "bugs": {
44
+ "url": "https://github.com/holepunchto/bare-fs/issues"
45
+ },
46
+ "homepage": "https://github.com/holepunchto/bare-fs#readme",
47
+ "engines": {
48
+ "bare": ">=1.16.0"
49
+ },
50
+ "dependencies": {
51
+ "bare-events": "^2.5.4",
52
+ "bare-path": "^3.0.0",
53
+ "bare-stream": "^2.6.4",
54
+ "bare-url": "^2.2.2",
55
+ "fast-fifo": "^1.3.2"
56
+ },
57
+ "devDependencies": {
58
+ "bare-buffer": "^3.0.2",
59
+ "bare-crypto": "^1.11.2",
60
+ "brittle": "^3.1.1",
61
+ "cmake-bare": "^1.1.7",
62
+ "lunte": "^1.6.0",
63
+ "prettier": "^3.4.1",
64
+ "prettier-config-holepunch": "^2.0.0"
65
+ },
66
+ "peerDependencies": {
67
+ "bare-buffer": "*"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "bare-buffer": {
71
+ "optional": true
72
+ }
73
+ }
74
+ }
node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare ADDED
Binary file (51.5 kB). View file
 
node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare ADDED
Binary file (66.6 kB). View file
 
node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare ADDED
Binary file (56.5 kB). View file
 
node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare ADDED
Binary file (61 kB). View file
 
node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare ADDED
Binary file (94.4 kB). View file
 
node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare ADDED
Binary file (60.7 kB). View file
 
node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare ADDED
Binary file (94.3 kB). View file
 
node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98c9cf4d3ff91c1da6c191452459b1276f936a0858293910544a701ef231131b
3
+ size 109864
node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare ADDED
Binary file (60.7 kB). View file
 
node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare ADDED
Binary file (58.6 kB). View file
 
node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare ADDED
Binary file (58.2 kB). View file
 
node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9643bea5293e64ea8f86cdb121addc8ccf2781b032ed2c2c240f86a1d905203
3
+ size 143360
node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16207c79cc1373e17fd41d4908cd5000bf8db530ec17ec8e79805c6ac9d4df6e
3
+ size 152576
node_modules/bare-fs/promises.d.ts ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import EventEmitter, { EventMap } from 'bare-events'
2
+ import Buffer, { BufferEncoding } from 'bare-buffer'
3
+ import {
4
+ constants,
5
+ AppendFileOptions,
6
+ CpOptions,
7
+ Dir,
8
+ Dirent,
9
+ Flag,
10
+ MkdirOptions,
11
+ OpendirOptions,
12
+ Path,
13
+ ReadFileOptions,
14
+ ReadStream,
15
+ ReadStreamOptions,
16
+ ReaddirOptions,
17
+ ReadlinkOptions,
18
+ RealpathOptions,
19
+ RmOptions,
20
+ StatFs,
21
+ Stats,
22
+ Watcher,
23
+ WatcherOptions,
24
+ WriteFileOptions,
25
+ WriteStream,
26
+ WriteStreamOptions
27
+ } from '.'
28
+
29
+ export { constants }
30
+
31
+ interface FileHandleEvents extends EventMap {
32
+ close: []
33
+ }
34
+
35
+ interface FileHandle extends EventEmitter<FileHandleEvents>, AsyncDisposable {
36
+ readonly fd: number
37
+
38
+ close(): Promise<void>
39
+
40
+ read(
41
+ buffer: Buffer | ArrayBufferView,
42
+ offset?: number,
43
+ len?: number,
44
+ pos?: number
45
+ ): Promise<number>
46
+
47
+ readv(buffers: ArrayBufferView[], position?: number): Promise<number>
48
+
49
+ write(
50
+ data: Buffer | ArrayBufferView,
51
+ offset?: number,
52
+ len?: number,
53
+ pos?: number
54
+ ): Promise<number>
55
+
56
+ write(data: string, pos?: number, encoding?: BufferEncoding): Promise<number>
57
+
58
+ stat(): Promise<Stats>
59
+
60
+ chmod(mode: string | number): Promise<void>
61
+
62
+ chown(uid: number, gid: number): Promise<void>
63
+
64
+ datasync(): Promise<void>
65
+
66
+ sync(): Promise<void>
67
+
68
+ truncate(len?: number): Promise<void>
69
+
70
+ utimes(atime: number | Date, mtime: number | Date): Promise<void>
71
+
72
+ createReadStream(opts?: ReadStreamOptions): ReadStream
73
+
74
+ createWriteStream(opts?: WriteStreamOptions): WriteStream
75
+ }
76
+
77
+ declare class FileHandle {
78
+ private constructor(fd: number)
79
+ }
80
+
81
+ export function open(
82
+ filepath: Path,
83
+ flags?: Flag | number,
84
+ mode?: string | number
85
+ ): Promise<FileHandle>
86
+
87
+ export function access(filepath: Path, mode?: number): Promise<void>
88
+
89
+ export function appendFile(
90
+ filepath: Path,
91
+ data: string | Buffer | ArrayBufferView,
92
+ opts?: AppendFileOptions
93
+ ): Promise<void>
94
+
95
+ export function appendFile(
96
+ filepath: Path,
97
+ data: string | Buffer | ArrayBufferView,
98
+ encoding: BufferEncoding
99
+ ): Promise<void>
100
+
101
+ export function chmod(filepath: Path, mode: string | number): Promise<void>
102
+
103
+ export function chown(filepath: Path, uid: number, gid: number): Promise<void>
104
+
105
+ export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
106
+
107
+ export function cp(src: Path, dst: Path, opts?: CpOptions): Promise<void>
108
+
109
+ export function lchown(filepath: Path, uid: number, gid: number): Promise<void>
110
+
111
+ export function lutimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
112
+
113
+ export function link(src: Path, dst: Path): Promise<void>
114
+
115
+ export function lstat(filepath: Path): Promise<Stats>
116
+
117
+ export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
118
+
119
+ export function mkdir(filepath: Path, mode: number): Promise<void>
120
+
121
+ export function mkdtemp(prefix: Path): Promise<string>
122
+
123
+ export function opendir(
124
+ filepath: Path,
125
+ opts: OpendirOptions & { encoding?: BufferEncoding }
126
+ ): Promise<Dir<string>>
127
+
128
+ export function opendir(
129
+ filepath: Path,
130
+ opts: OpendirOptions & { encoding: 'buffer' }
131
+ ): Promise<Dir<Buffer>>
132
+
133
+ export function opendir(filepath: Path, opts: OpendirOptions): Promise<Dir>
134
+
135
+ export function opendir(filepath: Path, encoding: BufferEncoding): Promise<Dir<string>>
136
+
137
+ export function opendir(filepath: Path, encoding: 'buffer'): Promise<Dir<Buffer>>
138
+
139
+ export function opendir(filepath: Path, encoding: BufferEncoding | 'buffer'): Promise<Dir>
140
+
141
+ export function opendir(filepath: Path): Promise<Dir<string>>
142
+
143
+ export function readFile(
144
+ filepath: Path,
145
+ opts: ReadFileOptions & { encoding: BufferEncoding }
146
+ ): Promise<string>
147
+
148
+ export function readFile(
149
+ filepath: Path,
150
+ opts: ReadFileOptions & { encoding?: 'buffer' }
151
+ ): Promise<Buffer>
152
+
153
+ export function readFile(filepath: Path, opts: ReadFileOptions): Promise<string | Buffer>
154
+
155
+ export function readFile(filepath: Path, encoding: BufferEncoding): Promise<string>
156
+
157
+ export function readFile(filepath: Path, encoding: 'buffer'): Promise<Buffer>
158
+
159
+ export function readFile(
160
+ filepath: Path,
161
+ encoding?: BufferEncoding | 'buffer'
162
+ ): Promise<string | Buffer>
163
+
164
+ export function readFile(filepath: Path): Promise<Buffer>
165
+
166
+ export function readdir(
167
+ filepath: Path,
168
+ opts: ReaddirOptions & { encoding?: BufferEncoding }
169
+ ): Promise<Dir<string>[] | string[]>
170
+
171
+ export function readdir(
172
+ filepath: Path,
173
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
174
+ ): Promise<Dir<string>[]>
175
+
176
+ export function readdir(
177
+ filepath: Path,
178
+ opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes?: false }
179
+ ): Promise<string[]>
180
+
181
+ export function readdir(
182
+ filepath: Path,
183
+ opts: ReaddirOptions & { encoding: 'buffer' }
184
+ ): Promise<Dir<Buffer>[] | Buffer[]>
185
+
186
+ export function readdir(
187
+ filepath: Path,
188
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
189
+ ): Promise<Dir<Buffer>[]>
190
+
191
+ export function readdir(
192
+ filepath: Path,
193
+ opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes?: false }
194
+ ): Promise<Buffer[]>
195
+
196
+ export function readdir(
197
+ filepath: Path,
198
+ opts: ReaddirOptions & { withFileTypes: true }
199
+ ): Promise<Dir<string | Buffer>[]>
200
+
201
+ export function readdir(
202
+ filepath: Path,
203
+ opts: ReaddirOptions & { withFileTypes?: false }
204
+ ): Promise<string[] | Buffer[]>
205
+
206
+ export function readdir(filepath: Path, opts: ReaddirOptions): Promise<Dir[] | string[] | Buffer[]>
207
+
208
+ export function readdir(filepath: Path, encoding: BufferEncoding): Promise<string[]>
209
+
210
+ export function readdir(filepath: Path, encoding: 'buffer'): Promise<Buffer[]>
211
+
212
+ export function readdir(
213
+ filepath: Path,
214
+ encoding: BufferEncoding | 'buffer'
215
+ ): Promise<string[] | Buffer[]>
216
+
217
+ export function readdir(filepath: Path): Promise<string[]>
218
+
219
+ export function readlink(
220
+ filepath: Path,
221
+ opts: ReadlinkOptions & { encoding?: BufferEncoding }
222
+ ): Promise<string>
223
+
224
+ export function readlink(
225
+ filepath: Path,
226
+ opts: ReadlinkOptions & { encoding: 'buffer' }
227
+ ): Promise<Buffer>
228
+
229
+ export function readlink(filepath: Path, opts: ReadlinkOptions): Promise<string | Buffer>
230
+
231
+ export function readlink(filepath: Path, encoding: BufferEncoding): Promise<string>
232
+
233
+ export function readlink(filepath: Path, encoding: 'buffer'): Promise<Buffer>
234
+
235
+ export function readlink(
236
+ filepath: Path,
237
+ encoding: BufferEncoding | 'buffer'
238
+ ): Promise<string | Buffer>
239
+
240
+ export function readlink(filepath: Path): Promise<string>
241
+
242
+ export function realpath(
243
+ filepath: Path,
244
+ opts: RealpathOptions & { encoding?: BufferEncoding }
245
+ ): Promise<string>
246
+
247
+ export function realpath(
248
+ filepath: Path,
249
+ opts: RealpathOptions & { encoding: 'buffer' }
250
+ ): Promise<Buffer>
251
+
252
+ export function realpath(filepath: Path, opts: RealpathOptions): Promise<string | Buffer>
253
+
254
+ export function realpath(filepath: Path, encoding: BufferEncoding): Promise<string>
255
+
256
+ export function realpath(filepath: Path, encoding: 'buffer'): Promise<Buffer>
257
+
258
+ export function realpath(
259
+ filepath: Path,
260
+ encoding: BufferEncoding | 'buffer'
261
+ ): Promise<string | Buffer>
262
+
263
+ export function realpath(filepath: Path): Promise<string>
264
+
265
+ export function rename(src: Path, dst: Path): Promise<void>
266
+
267
+ export function rm(filepath: Path, opts?: RmOptions): Promise<void>
268
+
269
+ export function rmdir(filepath: Path): Promise<void>
270
+
271
+ export function stat(filepath: Path): Promise<Stats>
272
+
273
+ export function statfs(filepath: Path): Promise<StatFs>
274
+
275
+ export function truncate(filepath: Path, len?: number): Promise<void>
276
+
277
+ export function symlink(target: Path, filepath: Path, type?: string | number): Promise<void>
278
+
279
+ export function unlink(filepath: Path): Promise<void>
280
+
281
+ export function utimes(filepath: Path, atime: number | Date, mtime: number | Date): Promise<void>
282
+
283
+ export function watch(
284
+ filepath: Path,
285
+ opts: WatcherOptions & { encoding?: BufferEncoding }
286
+ ): Watcher<string>
287
+
288
+ export function watch(
289
+ filepath: Path,
290
+ opts: WatcherOptions & { encoding: 'buffer' }
291
+ ): Watcher<Buffer>
292
+
293
+ export function watch(filepath: Path, opts: WatcherOptions): Watcher
294
+
295
+ export function watch(filepath: Path, encoding: BufferEncoding): Watcher<string>
296
+
297
+ export function watch(filepath: Path, encoding: 'buffer'): Watcher<Buffer>
298
+
299
+ export function watch(filepath: Path, encoding: BufferEncoding | 'buffer'): Watcher
300
+
301
+ export function watch(filepath: Path): Watcher<string>
302
+
303
+ export function writeFile(
304
+ filepath: Path,
305
+ data: string | Buffer | ArrayBufferView,
306
+ opts?: WriteFileOptions
307
+ ): Promise<void>
308
+
309
+ export function writeFile(
310
+ filepath: Path,
311
+ data: string | Buffer | ArrayBufferView,
312
+ encoding: BufferEncoding
313
+ ): Promise<void>
node_modules/bare-fs/promises.js ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const EventEmitter = require('bare-events')
2
+ const fs = require('.')
3
+
4
+ class FileHandle extends EventEmitter {
5
+ constructor(fd) {
6
+ super()
7
+
8
+ this.fd = fd
9
+ }
10
+
11
+ async close() {
12
+ await fs.close(this.fd)
13
+
14
+ this.fd = -1
15
+ this.emit('close')
16
+ }
17
+
18
+ async read(buffer, ...args) {
19
+ return {
20
+ bytesRead: await fs.read(this.fd, buffer, ...args),
21
+ buffer
22
+ }
23
+ }
24
+
25
+ async readv(buffers, ...args) {
26
+ return {
27
+ bytesRead: await fs.readv(this.fd, buffers, ...args),
28
+ buffers
29
+ }
30
+ }
31
+
32
+ async write(buffer, ...args) {
33
+ return {
34
+ bytesWritten: await fs.write(this.fd, buffer, ...args),
35
+ buffer
36
+ }
37
+ }
38
+
39
+ async writev(buffers, ...args) {
40
+ return {
41
+ bytesWritten: await fs.writev(this.fd, buffers, ...args),
42
+ buffers
43
+ }
44
+ }
45
+
46
+ async stat() {
47
+ return fs.fstat(this.fd)
48
+ }
49
+
50
+ async chmod(mode) {
51
+ await fs.fchmod(this.fd, mode)
52
+ }
53
+
54
+ async chown(uid, gid) {
55
+ await fs.fchown(this.fd, uid, gid)
56
+ }
57
+
58
+ async datasync() {
59
+ return fs.fdatasync(this.fd)
60
+ }
61
+
62
+ async sync() {
63
+ return fs.fsync(this.fd)
64
+ }
65
+
66
+ async truncate(len) {
67
+ await fs.ftruncate(this.fd, len)
68
+ }
69
+
70
+ async utimes(atime, mtime) {
71
+ await fs.futimes(this.fd, atime, mtime)
72
+ }
73
+
74
+ createReadStream(opts) {
75
+ return fs.createReadStream(null, { ...opts, fd: this.fd })
76
+ }
77
+
78
+ createWriteStream(opts) {
79
+ return fs.createWriteStream(null, { ...opts, fd: this.fd })
80
+ }
81
+
82
+ async [Symbol.asyncDispose]() {
83
+ await this.close()
84
+ }
85
+ }
86
+
87
+ exports.open = async function open(filepath, flags, mode) {
88
+ return new FileHandle(await fs.open(filepath, flags, mode))
89
+ }
90
+
91
+ exports.access = fs.access
92
+ exports.appendFile = fs.appendFile
93
+ exports.chmod = fs.chmod
94
+ exports.chown = fs.chown
95
+ exports.constants = fs.constants
96
+ exports.copyFile = fs.copyFile
97
+ exports.cp = fs.cp
98
+ exports.lchown = fs.lchown
99
+ exports.lutimes = fs.lutimes
100
+ exports.link = fs.link
101
+ exports.lstat = fs.lstat
102
+ exports.mkdir = fs.mkdir
103
+ exports.mkdtemp = fs.mkdtemp
104
+ exports.opendir = fs.opendir
105
+ exports.readFile = fs.readFile
106
+ exports.readdir = fs.readdir
107
+ exports.readlink = fs.readlink
108
+ exports.realpath = fs.realpath
109
+ exports.rename = fs.rename
110
+ exports.rm = fs.rm
111
+ exports.rmdir = fs.rmdir
112
+ exports.stat = fs.stat
113
+ exports.statfs = fs.statfs
114
+ exports.truncate = fs.truncate
115
+ exports.symlink = fs.symlink
116
+ exports.unlink = fs.unlink
117
+ exports.utimes = fs.utimes
118
+ exports.watch = fs.watch
119
+ exports.writeFile = fs.writeFile
node_modules/bare-os/CMakeLists.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cmake_minimum_required(VERSION 4.0)
2
+
3
+ find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
4
+
5
+ project(bare_os C)
6
+
7
+ add_bare_module(bare_os)
8
+
9
+ target_sources(
10
+ ${bare_os}
11
+ PRIVATE
12
+ binding.c
13
+ )
node_modules/bare-os/LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
node_modules/bare-os/README.md ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # bare-os
2
+
3
+ Operating system utilities for Bare. The API closely follows that of the Node.js `os` module.
4
+
5
+ ```
6
+ npm i bare-os
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```js
12
+ const os = require('bare-os')
13
+
14
+ console.log(os.platform()) // 'darwin', 'linux', 'win32', ...
15
+ console.log(os.arch()) // 'arm64', 'x64', ...
16
+ console.log(os.homedir())
17
+ console.log(os.tmpdir())
18
+ console.log(os.hostname())
19
+ console.log(os.networkInterfaces())
20
+ ```
21
+
22
+ ## API
23
+
24
+ #### `os.constants`
25
+
26
+ An object containing the following properties:
27
+
28
+ - `signals` - Signal constants such as `SIGTERM` and `SIGKILL`.
29
+ - `errnos` - Error number constants.
30
+ - `priority` - Process priority constants.
31
+
32
+ These are also available as a separate module:
33
+
34
+ ```js
35
+ const constants = require('bare-os/constants')
36
+ ```
37
+
38
+ #### `os.EOL`
39
+
40
+ The platform-specific end-of-line marker. `'\r\n'` on Windows, `'\n'` everywhere else.
41
+
42
+ #### `os.devNull`
43
+
44
+ The platform-specific path to the null device. `'\\\\.\\nul'` on Windows, `'/dev/null'` everywhere else.
45
+
46
+ #### `const p = os.platform()`
47
+
48
+ Returns the operating system platform as a string. Possible values include `'android'`, `'darwin'`, `'ios'`, `'linux'`, and `'win32'`.
49
+
50
+ #### `const a = os.arch()`
51
+
52
+ Returns the CPU architecture as a string. Possible values include `'arm'`, `'arm64'`, `'ia32'`, and `'x64'`.
53
+
54
+ #### `const t = os.type()`
55
+
56
+ Returns the operating system name as returned by `uname(3)`.
57
+
58
+ #### `const v = os.version()`
59
+
60
+ Returns the operating system version.
61
+
62
+ #### `const r = os.release()`
63
+
64
+ Returns the operating system release.
65
+
66
+ #### `const m = os.machine()`
67
+
68
+ Returns the machine type as a string.
69
+
70
+ #### `const p = os.execPath()`
71
+
72
+ Returns the absolute path of the executable that started the process.
73
+
74
+ #### `const id = os.pid()`
75
+
76
+ Returns the process ID.
77
+
78
+ #### `const id = os.ppid()`
79
+
80
+ Returns the parent process ID.
81
+
82
+ #### `const dir = os.cwd()`
83
+
84
+ Returns the current working directory.
85
+
86
+ #### `os.chdir(dir)`
87
+
88
+ Changes the current working directory to `dir`.
89
+
90
+ #### `const dir = os.tmpdir()`
91
+
92
+ Returns the operating system's default directory for temporary files.
93
+
94
+ #### `const dir = os.homedir()`
95
+
96
+ Returns the home directory of the current user.
97
+
98
+ #### `const name = os.hostname()`
99
+
100
+ Returns the hostname of the operating system.
101
+
102
+ #### `const interfaces = os.networkInterfaces()`
103
+
104
+ Returns an object containing network interfaces that have been assigned a network address. Each key on the returned object identifies a network interface. The associated value is an array of objects with the following properties:
105
+
106
+ - `address` - The assigned IPv4 or IPv6 address.
107
+ - `netmask` - The IPv4 or IPv6 network mask.
108
+ - `family` - Either `'IPv4'` or `'IPv6'`.
109
+ - `cidr` - The assigned IPv4 or IPv6 address with the routing prefix in CIDR notation.
110
+ - `mac` - The MAC address of the network interface.
111
+ - `internal` - `true` if the network interface is a loopback or similar interface that is not remotely accessible; otherwise `false`.
112
+ - `scopeid` - The numeric IPv6 scope ID. Only specified when `family` is `'IPv6'`.
113
+
114
+ #### `os.kill(pid[, signal])`
115
+
116
+ Sends `signal` to the process identified by `pid`. `signal` can be a string or a number. Defaults to `'SIGTERM'`.
117
+
118
+ #### `const info = os.userInfo([uid])`
119
+
120
+ Returns information about a current user. The `uid` value defaults to the current effective uid. The returned object has the following properties:
121
+
122
+ - `uid` - The user ID.
123
+ - `gid` - The group ID.
124
+ - `username` - The username.
125
+ - `homedir` - The home directory.
126
+ - `shell` - The shell, or `null` if unavailable.
127
+
128
+ #### `const info = os.groupInfo([gid])`
129
+
130
+ Returns information about a group. The `gid` value defaults to the effective group ID of the calling process. The returned object has the following properties:
131
+
132
+ - `groupname` - The group name.
133
+ - `gid` - The group ID.
134
+ - `members` - List with the names of group members.
135
+
136
+ #### `const e = os.endianness()`
137
+
138
+ Returns `'LE'` on little-endian systems and `'BE'` on big-endian systems.
139
+
140
+ #### `const n = os.availableParallelism()`
141
+
142
+ Returns the number of logical CPU cores available to the process.
143
+
144
+ #### `const usage = os.cpuUsage([previous])`
145
+
146
+ Returns an object with `user` and `system` properties, each representing CPU time in microseconds. If `previous` is provided, the returned values are relative to it.
147
+
148
+ #### `const usage = os.threadCpuUsage([previous])`
149
+
150
+ Like `os.cpuUsage()` but for the current thread only.
151
+
152
+ #### `const usage = os.resourceUsage()`
153
+
154
+ Returns an object describing the resource usage of the current process. The returned object has the following properties:
155
+
156
+ - `userCPUTime` - User CPU time in microseconds.
157
+ - `systemCPUTime` - System CPU time in microseconds.
158
+ - `maxRSS` - Maximum resident set size in bytes.
159
+ - `sharedMemorySize` - Shared memory size.
160
+ - `unsharedDataSize` - Unshared data size.
161
+ - `unsharedStackSize` - Unshared stack size.
162
+ - `minorPageFault` - Minor page faults.
163
+ - `majorPageFault` - Major page faults.
164
+ - `swappedOut` - Swap count.
165
+ - `fsRead` - File system reads.
166
+ - `fsWrite` - File system writes.
167
+ - `ipcSent` - IPC messages sent.
168
+ - `ipcReceived` - IPC messages received.
169
+ - `signalsCount` - Signals received.
170
+ - `voluntaryContextSwitches` - Voluntary context switches.
171
+ - `involuntaryContextSwitches` - Involuntary context switches.
172
+
173
+ #### `const usage = os.memoryUsage()`
174
+
175
+ Returns an object describing the memory usage of the process. The returned object has the following properties:
176
+
177
+ - `rss` - Resident set size in bytes.
178
+ - `heapTotal` - Total heap size in bytes.
179
+ - `heapUsed` - Used heap size in bytes.
180
+ - `external` - Memory usage of C++ objects bound to JavaScript objects.
181
+
182
+ #### `const bytes = os.freemem()`
183
+
184
+ Returns the amount of free system memory in bytes.
185
+
186
+ #### `const bytes = os.totalmem()`
187
+
188
+ Returns the total amount of system memory in bytes.
189
+
190
+ #### `const bytes = os.availableMemory()`
191
+
192
+ Returns an estimate of the amount of memory available for the process in bytes.
193
+
194
+ #### `const bytes = os.constrainedMemory()`
195
+
196
+ Returns the amount of memory available to the process under resource constraints, such as cgroups.
197
+
198
+ #### `const seconds = os.uptime()`
199
+
200
+ Returns the system uptime in seconds.
201
+
202
+ #### `const avgs = os.loadavg()`
203
+
204
+ Returns an array containing the 1, 5, and 15 minute load averages.
205
+
206
+ #### `const list = os.cpus()`
207
+
208
+ Returns an array of objects describing each logical CPU core. Each object has the following properties:
209
+
210
+ - `model` - The CPU model.
211
+ - `speed` - The CPU speed in MHz.
212
+ - `times` - An object with `user`, `nice`, `sys`, `idle`, and `irq` CPU time values in milliseconds.
213
+
214
+ #### `const title = os.getProcessTitle()`
215
+
216
+ Returns the current process title.
217
+
218
+ #### `os.setProcessTitle(title)`
219
+
220
+ Sets the process title. `title` is coerced to a string and must be shorter than 256 characters.
221
+
222
+ #### `const priority = os.getPriority([pid])`
223
+
224
+ Returns the scheduling priority of the process specified by `pid`. Defaults to `0`, meaning the current process.
225
+
226
+ #### `os.setPriority([pid, ]priority)`
227
+
228
+ Sets the scheduling priority of the process specified by `pid`. If `pid` is omitted, the priority of the current process is set.
229
+
230
+ #### `const keys = os.getEnvKeys()`
231
+
232
+ Returns an array of the names of all environment variables.
233
+
234
+ #### `const value = os.getEnv(name)`
235
+
236
+ Returns the value of the environment variable `name`, or `undefined` if it is not set.
237
+
238
+ #### `const exists = os.hasEnv(name)`
239
+
240
+ Returns `true` if the environment variable `name` is set, otherwise `false`.
241
+
242
+ #### `os.setEnv(name, value)`
243
+
244
+ Sets the environment variable `name` to `value`.
245
+
246
+ #### `os.unsetEnv(name)`
247
+
248
+ Removes the environment variable `name`.
249
+
250
+ ## License
251
+
252
+ Apache-2.0
node_modules/bare-os/binding.c ADDED
@@ -0,0 +1,1538 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <assert.h>
2
+ #include <bare.h>
3
+ #include <js.h>
4
+ #include <stdlib.h>
5
+ #include <utf.h>
6
+ #include <uv.h>
7
+
8
+ #if !defined(BARE_PLATFORM_WIN32)
9
+ #include <unistd.h> // getegid
10
+ #endif
11
+
12
+ static uv_rwlock_t bare_os_env_lock;
13
+
14
+ static uv_once_t bare_os_env_lock_guard = UV_ONCE_INIT;
15
+
16
+ static void
17
+ bare_os__on_env_lock_init(void) {
18
+ int err = uv_rwlock_init(&bare_os_env_lock);
19
+ assert(err == 0);
20
+ }
21
+
22
+ static js_value_t *
23
+ bare_os_type(js_env_t *env, js_callback_info_t *info) {
24
+ int err;
25
+
26
+ uv_utsname_t buffer;
27
+ err = uv_os_uname(&buffer);
28
+ if (err < 0) {
29
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
30
+ assert(err == 0);
31
+
32
+ return NULL;
33
+ }
34
+
35
+ js_value_t *result;
36
+ err = js_create_string_utf8(env, (utf8_t *) buffer.sysname, -1, &result);
37
+ assert(err == 0);
38
+
39
+ return result;
40
+ }
41
+
42
+ static js_value_t *
43
+ bare_os_version(js_env_t *env, js_callback_info_t *info) {
44
+ int err;
45
+
46
+ uv_utsname_t buffer;
47
+ err = uv_os_uname(&buffer);
48
+ if (err < 0) {
49
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
50
+ assert(err == 0);
51
+
52
+ return NULL;
53
+ }
54
+
55
+ js_value_t *result;
56
+ err = js_create_string_utf8(env, (utf8_t *) buffer.version, -1, &result);
57
+ assert(err == 0);
58
+
59
+ return result;
60
+ }
61
+
62
+ static js_value_t *
63
+ bare_os_release(js_env_t *env, js_callback_info_t *info) {
64
+ int err;
65
+
66
+ uv_utsname_t buffer;
67
+ err = uv_os_uname(&buffer);
68
+ if (err < 0) {
69
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
70
+ assert(err == 0);
71
+
72
+ return NULL;
73
+ }
74
+
75
+ js_value_t *result;
76
+ err = js_create_string_utf8(env, (utf8_t *) buffer.release, -1, &result);
77
+ assert(err == 0);
78
+
79
+ return result;
80
+ }
81
+
82
+ static js_value_t *
83
+ bare_os_machine(js_env_t *env, js_callback_info_t *info) {
84
+ int err;
85
+
86
+ uv_utsname_t buffer;
87
+ err = uv_os_uname(&buffer);
88
+ if (err < 0) {
89
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
90
+ assert(err == 0);
91
+
92
+ return NULL;
93
+ }
94
+
95
+ js_value_t *result;
96
+ err = js_create_string_utf8(env, (utf8_t *) buffer.machine, -1, &result);
97
+ assert(err == 0);
98
+
99
+ return result;
100
+ }
101
+
102
+ static js_value_t *
103
+ bare_os_exec_path(js_env_t *env, js_callback_info_t *info) {
104
+ int err;
105
+
106
+ size_t len = 4096;
107
+ char exec_path[4096];
108
+
109
+ err = uv_exepath(exec_path, &len);
110
+ if (err < 0) {
111
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
112
+ assert(err == 0);
113
+
114
+ return NULL;
115
+ }
116
+
117
+ js_value_t *result;
118
+ err = js_create_string_utf8(env, (utf8_t *) exec_path, len, &result);
119
+ assert(err == 0);
120
+
121
+ return result;
122
+ }
123
+
124
+ static js_value_t *
125
+ bare_os_pid(js_env_t *env, js_callback_info_t *info) {
126
+ int err;
127
+
128
+ js_value_t *result;
129
+ err = js_create_uint32(env, uv_os_getpid(), &result);
130
+ assert(err == 0);
131
+
132
+ return result;
133
+ }
134
+
135
+ static js_value_t *
136
+ bare_os_ppid(js_env_t *env, js_callback_info_t *info) {
137
+ int err;
138
+
139
+ js_value_t *result;
140
+ err = js_create_uint32(env, uv_os_getppid(), &result);
141
+ assert(err == 0);
142
+
143
+ return result;
144
+ }
145
+
146
+ static js_value_t *
147
+ bare_os_cwd(js_env_t *env, js_callback_info_t *info) {
148
+ int err;
149
+
150
+ size_t len = 4096;
151
+ char cwd[4096];
152
+
153
+ err = uv_cwd(cwd, &len);
154
+ if (err < 0) {
155
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
156
+ assert(err == 0);
157
+
158
+ return NULL;
159
+ }
160
+
161
+ js_value_t *result;
162
+ err = js_create_string_utf8(env, (utf8_t *) cwd, len, &result);
163
+ assert(err == 0);
164
+
165
+ return result;
166
+ }
167
+
168
+ static js_value_t *
169
+ bare_os_chdir(js_env_t *env, js_callback_info_t *info) {
170
+ int err;
171
+
172
+ size_t argc = 1;
173
+ js_value_t *argv[1];
174
+
175
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
176
+ assert(err == 0);
177
+
178
+ assert(argc == 1);
179
+
180
+ utf8_t dir[4096];
181
+ err = js_get_value_string_utf8(env, argv[0], dir, 4096, NULL);
182
+ assert(err == 0);
183
+
184
+ err = uv_chdir((char *) dir);
185
+ if (err < 0) {
186
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
187
+ assert(err == 0);
188
+
189
+ return NULL;
190
+ }
191
+
192
+ return NULL;
193
+ }
194
+
195
+ static js_value_t *
196
+ bare_os_tmpdir(js_env_t *env, js_callback_info_t *info) {
197
+ int err;
198
+
199
+ size_t len = 4096;
200
+ char tmpdir[4096];
201
+
202
+ err = uv_os_tmpdir(tmpdir, &len);
203
+ if (err < 0) {
204
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
205
+ assert(err == 0);
206
+
207
+ return NULL;
208
+ }
209
+
210
+ js_value_t *result;
211
+ err = js_create_string_utf8(env, (utf8_t *) tmpdir, len, &result);
212
+ assert(err == 0);
213
+
214
+ return result;
215
+ }
216
+
217
+ static js_value_t *
218
+ bare_os_homedir(js_env_t *env, js_callback_info_t *info) {
219
+ int err;
220
+
221
+ size_t len = 4096;
222
+ char homedir[4096];
223
+
224
+ err = uv_os_homedir(homedir, &len);
225
+ if (err < 0) {
226
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
227
+ assert(err == 0);
228
+
229
+ return NULL;
230
+ }
231
+
232
+ js_value_t *result;
233
+ err = js_create_string_utf8(env, (utf8_t *) homedir, len, &result);
234
+ assert(err == 0);
235
+
236
+ return result;
237
+ }
238
+
239
+ static js_value_t *
240
+ bare_os_hostname(js_env_t *env, js_callback_info_t *info) {
241
+ int err;
242
+
243
+ size_t len = UV_MAXHOSTNAMESIZE;
244
+ char hostname[UV_MAXHOSTNAMESIZE];
245
+
246
+ err = uv_os_gethostname(hostname, &len);
247
+ if (err < 0) {
248
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
249
+ assert(err == 0);
250
+
251
+ return NULL;
252
+ }
253
+
254
+ js_value_t *result;
255
+ err = js_create_string_utf8(env, (utf8_t *) hostname, len, &result);
256
+ assert(err == 0);
257
+
258
+ return result;
259
+ }
260
+
261
+ static js_value_t *
262
+ bare_os_user_info(js_env_t *env, js_callback_info_t *info) {
263
+ int err;
264
+
265
+ size_t argc = 1;
266
+ js_value_t *argv[1];
267
+
268
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
269
+ assert(err == 0);
270
+
271
+ assert(argc == 0 || argc == 1);
272
+
273
+ bool uid_undefined;
274
+ err = js_is_undefined(env, argv[0], &uid_undefined);
275
+ assert(err == 0);
276
+
277
+ uv_passwd_t pwd;
278
+ if (uid_undefined) {
279
+ err = uv_os_get_passwd(&pwd);
280
+ } else {
281
+ uint32_t uid;
282
+ err = js_get_value_uint32(env, argv[0], &uid);
283
+ assert(err == 0);
284
+
285
+ err = uv_os_get_passwd2(&pwd, uid);
286
+ }
287
+
288
+ if (err != 0) {
289
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
290
+ assert(err == 0);
291
+
292
+ return NULL;
293
+ }
294
+
295
+ js_value_t *result;
296
+ err = js_create_object(env, &result);
297
+ assert(err == 0);
298
+
299
+ js_value_t *uid;
300
+ err = js_create_int32(env, pwd.uid, &uid);
301
+ assert(err == 0);
302
+
303
+ err = js_set_named_property(env, result, "uid", uid);
304
+ assert(err == 0);
305
+
306
+ js_value_t *gid;
307
+ err = js_create_int32(env, pwd.gid, &gid);
308
+ assert(err == 0);
309
+
310
+ err = js_set_named_property(env, result, "gid", gid);
311
+ assert(err == 0);
312
+
313
+ js_value_t *username;
314
+ err = js_create_string_utf8(env, (utf8_t *) pwd.username, strlen(pwd.username), &username);
315
+ assert(err == 0);
316
+
317
+ err = js_set_named_property(env, result, "username", username);
318
+ assert(err == 0);
319
+
320
+ js_value_t *homedir;
321
+ err = js_create_string_utf8(env, (utf8_t *) pwd.homedir, strlen(pwd.homedir), &homedir);
322
+ assert(err == 0);
323
+
324
+ err = js_set_named_property(env, result, "homedir", homedir);
325
+ assert(err == 0);
326
+
327
+ js_value_t *shell;
328
+
329
+ if (pwd.shell == NULL) {
330
+ err = js_get_null(env, &shell);
331
+ assert(err == 0);
332
+ } else {
333
+ err = js_create_string_utf8(env, (utf8_t *) pwd.shell, -1, &shell);
334
+ assert(err == 0);
335
+ }
336
+
337
+ err = js_set_named_property(env, result, "shell", shell);
338
+ assert(err == 0);
339
+
340
+ uv_os_free_passwd(&pwd);
341
+
342
+ return result;
343
+ }
344
+
345
+ static int
346
+ bare_os__population_count(uint32_t num) {
347
+ int result = 0;
348
+
349
+ while (num != 0) {
350
+ result++;
351
+ num &= num - 1;
352
+ }
353
+
354
+ return result;
355
+ }
356
+
357
+ static js_value_t *
358
+ bare_os_network_interfaces(js_env_t *env, js_callback_info_t *info) {
359
+ int err;
360
+
361
+ uv_interface_address_t *addresses;
362
+ int len;
363
+ err = uv_interface_addresses(&addresses, &len);
364
+ if (err < 0) {
365
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
366
+ assert(err == 0);
367
+
368
+ return NULL;
369
+ }
370
+
371
+ js_value_t *result;
372
+ err = js_create_array_with_length(env, len, &result);
373
+ assert(err == 0);
374
+
375
+ for (size_t i = 0, n = len; i < n; i++) {
376
+ uv_interface_address_t address = addresses[i];
377
+
378
+ uint32_t family = address.address.address4.sin_family;
379
+
380
+ if (family != AF_INET && family != AF_INET6) {
381
+ continue;
382
+ }
383
+
384
+ js_value_t *item;
385
+ err = js_create_object(env, &item);
386
+ assert(err == 0);
387
+
388
+ js_value_t *val;
389
+
390
+ err = js_create_string_utf8(env, (utf8_t *) address.name, -1, &val);
391
+ assert(err == 0);
392
+
393
+ err = js_set_named_property(env, item, "name", val);
394
+ assert(err == 0);
395
+
396
+ char address_ip[INET6_ADDRSTRLEN];
397
+ char netmask_ip[INET6_ADDRSTRLEN];
398
+ char family_string[5];
399
+
400
+ char cidr[INET6_ADDRSTRLEN + 8];
401
+ uint32_t cidr_value = 0;
402
+
403
+ if (family == AF_INET) {
404
+ err = uv_ip4_name(&address.address.address4, address_ip, sizeof(address_ip));
405
+ assert(err == 0);
406
+
407
+ err = uv_ip4_name(&address.netmask.netmask4, netmask_ip, sizeof(netmask_ip));
408
+ assert(err == 0);
409
+
410
+ strcpy(family_string, "IPv4");
411
+
412
+ cidr_value = bare_os__population_count(address.netmask.netmask4.sin_addr.s_addr);
413
+ } else {
414
+ err = uv_ip6_name(&address.address.address6, address_ip, sizeof(address_ip));
415
+ assert(err == 0);
416
+
417
+ err = uv_ip6_name(&address.netmask.netmask6, netmask_ip, sizeof(netmask_ip));
418
+ assert(err == 0);
419
+
420
+ strcpy(family_string, "IPv6");
421
+
422
+ for (size_t i = 0; i < 16; i++) {
423
+ uint32_t count = bare_os__population_count(address.netmask.netmask6.sin6_addr.s6_addr[i]);
424
+
425
+ if (count == 0) break;
426
+
427
+ cidr_value += count;
428
+ }
429
+ }
430
+
431
+ err = js_create_string_utf8(env, (utf8_t *) address_ip, -1, &val);
432
+ assert(err == 0);
433
+
434
+ err = js_set_named_property(env, item, "address", val);
435
+ assert(err == 0);
436
+
437
+ err = js_create_string_utf8(env, (utf8_t *) netmask_ip, -1, &val);
438
+ assert(err == 0);
439
+
440
+ err = js_set_named_property(env, item, "netmask", val);
441
+ assert(err == 0);
442
+
443
+ err = js_create_string_utf8(env, (utf8_t *) family_string, -1, &val);
444
+ assert(err == 0);
445
+
446
+ err = js_set_named_property(env, item, "family", val);
447
+ assert(err == 0);
448
+
449
+ err = snprintf(cidr, sizeof(cidr), "%s/%d", address_ip, cidr_value);
450
+ assert(err > 0);
451
+
452
+ err = js_create_string_utf8(env, (utf8_t *) cidr, -1, &val);
453
+ assert(err == 0);
454
+
455
+ err = js_set_named_property(env, item, "cidr", val);
456
+ assert(err == 0);
457
+
458
+ char mac[18];
459
+ err = snprintf(
460
+ mac,
461
+ sizeof(mac),
462
+ "%02x:%02x:%02x:%02x:%02x:%02x",
463
+ (unsigned char) address.phys_addr[0],
464
+ (unsigned char) address.phys_addr[1],
465
+ (unsigned char) address.phys_addr[2],
466
+ (unsigned char) address.phys_addr[3],
467
+ (unsigned char) address.phys_addr[4],
468
+ (unsigned char) address.phys_addr[5]
469
+ );
470
+ assert(err > 0);
471
+
472
+ err = js_create_string_utf8(env, (utf8_t *) mac, -1, &val);
473
+ assert(err == 0);
474
+
475
+ err = js_set_named_property(env, item, "mac", val);
476
+ assert(err == 0);
477
+
478
+ err = js_get_boolean(env, address.is_internal == 1, &val);
479
+ assert(err == 0);
480
+
481
+ err = js_set_named_property(env, item, "internal", val);
482
+ assert(err == 0);
483
+
484
+ if (family == AF_INET6) {
485
+ err = js_create_uint32(env, address.address.address6.sin6_scope_id, &val);
486
+ assert(err == 0);
487
+
488
+ err = js_set_named_property(env, item, "scopeid", val);
489
+ assert(err == 0);
490
+ }
491
+
492
+ err = js_set_element(env, result, i, item);
493
+ assert(err == 0);
494
+ }
495
+
496
+ uv_free_interface_addresses(addresses, len);
497
+
498
+ return result;
499
+ }
500
+
501
+ static js_value_t *
502
+ bare_os_kill(js_env_t *env, js_callback_info_t *info) {
503
+ int err;
504
+
505
+ size_t argc = 2;
506
+ js_value_t *argv[2];
507
+
508
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
509
+ assert(err == 0);
510
+
511
+ assert(argc == 2);
512
+
513
+ uint32_t pid;
514
+ err = js_get_value_uint32(env, argv[0], &pid);
515
+ assert(err == 0);
516
+
517
+ uint32_t signum;
518
+ err = js_get_value_uint32(env, argv[1], &signum);
519
+ assert(err == 0);
520
+
521
+ err = uv_kill(pid, signum);
522
+ if (err < 0) {
523
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
524
+ assert(err == 0);
525
+
526
+ return NULL;
527
+ }
528
+
529
+ return NULL;
530
+ }
531
+
532
+ static js_value_t *
533
+ bare_os_available_parallelism(js_env_t *env, js_callback_info_t *info) {
534
+ int err;
535
+
536
+ js_value_t *result;
537
+ err = js_create_int64(env, uv_available_parallelism(), &result);
538
+ assert(err == 0);
539
+
540
+ return result;
541
+ }
542
+
543
+ static js_value_t *
544
+ bare_os_cpu_usage(js_env_t *env, js_callback_info_t *info) {
545
+ int err;
546
+
547
+ uv_rusage_t usage;
548
+ err = uv_getrusage(&usage);
549
+ assert(err == 0);
550
+
551
+ js_value_t *result;
552
+ err = js_create_object(env, &result);
553
+ assert(err == 0);
554
+
555
+ #define V(name, property) \
556
+ { \
557
+ uv_timeval_t time = usage.ru_##property; \
558
+ \
559
+ js_value_t *value; \
560
+ err = js_create_int64(env, time.tv_sec * 1e6 + time.tv_usec, &value); \
561
+ assert(err == 0); \
562
+ \
563
+ err = js_set_named_property(env, result, name, value); \
564
+ assert(err == 0); \
565
+ }
566
+
567
+ V("user", utime)
568
+ V("system", stime)
569
+ #undef V
570
+
571
+ return result;
572
+ }
573
+
574
+ static js_value_t *
575
+ bare_os_cpu_usage_thread(js_env_t *env, js_callback_info_t *info) {
576
+ int err;
577
+
578
+ uv_rusage_t usage;
579
+ err = uv_getrusage_thread(&usage);
580
+ assert(err == 0);
581
+
582
+ js_value_t *result;
583
+ err = js_create_object(env, &result);
584
+ assert(err == 0);
585
+
586
+ #define V(name, property) \
587
+ { \
588
+ uv_timeval_t time = usage.ru_##property; \
589
+ \
590
+ js_value_t *value; \
591
+ err = js_create_int64(env, time.tv_sec * 1e6 + time.tv_usec, &value); \
592
+ assert(err == 0); \
593
+ \
594
+ err = js_set_named_property(env, result, name, value); \
595
+ assert(err == 0); \
596
+ }
597
+
598
+ V("user", utime)
599
+ V("system", stime)
600
+ #undef V
601
+
602
+ return result;
603
+ }
604
+
605
+ static js_value_t *
606
+ bare_os_resource_usage(js_env_t *env, js_callback_info_t *info) {
607
+ int err;
608
+
609
+ uv_rusage_t usage;
610
+ err = uv_getrusage(&usage);
611
+ assert(err == 0);
612
+
613
+ js_value_t *result;
614
+ err = js_create_object(env, &result);
615
+ assert(err == 0);
616
+
617
+ #define V(name, property) \
618
+ { \
619
+ uv_timeval_t time = usage.ru_##property; \
620
+ \
621
+ js_value_t *value; \
622
+ err = js_create_int64(env, time.tv_sec * 1e6 + time.tv_usec, &value); \
623
+ assert(err == 0); \
624
+ \
625
+ err = js_set_named_property(env, result, name, value); \
626
+ assert(err == 0); \
627
+ }
628
+
629
+ V("userCPUTime", utime)
630
+ V("systemCPUTime", stime)
631
+ #undef V
632
+
633
+ #define V(name, property) \
634
+ { \
635
+ js_value_t *value; \
636
+ err = js_create_int64(env, usage.ru_##property, &value); \
637
+ assert(err == 0); \
638
+ \
639
+ err = js_set_named_property(env, result, name, value); \
640
+ assert(err == 0); \
641
+ }
642
+
643
+ V("maxRSS", maxrss)
644
+ V("sharedMemorySize", ixrss)
645
+ V("unsharedDataSize", idrss)
646
+ V("unsharedStackSize", isrss)
647
+ V("minorPageFault", minflt)
648
+ V("majorPageFault", majflt)
649
+ V("swappedOut", nswap)
650
+ V("fsRead", inblock)
651
+ V("fsWrite", oublock)
652
+ V("ipcSent", msgsnd)
653
+ V("ipcReceived", msgrcv)
654
+ V("signalsCount", nsignals)
655
+ V("voluntaryContextSwitches", nvcsw)
656
+ V("involuntaryContextSwitches", nivcsw)
657
+ #undef V
658
+
659
+ return result;
660
+ }
661
+
662
+ static js_value_t *
663
+ bare_os_memory_usage(js_env_t *env, js_callback_info_t *info) {
664
+ int err;
665
+
666
+ js_heap_statistics_t stats = {
667
+ .version = 1,
668
+
669
+ // Since 0
670
+ .total_heap_size = -1,
671
+ .used_heap_size = -1,
672
+
673
+ // Since 1
674
+ .external_memory = -1,
675
+ };
676
+
677
+ err = js_get_heap_statistics(env, &stats);
678
+ assert(err == 0);
679
+
680
+ js_value_t *result;
681
+ err = js_create_object(env, &result);
682
+ assert(err == 0);
683
+
684
+ size_t rss;
685
+ err = uv_resident_set_memory(&rss);
686
+ assert(err == 0);
687
+
688
+ js_value_t *value;
689
+ err = js_create_int64(env, rss, &value);
690
+ assert(err == 0);
691
+
692
+ err = js_set_named_property(env, result, "rss", value);
693
+ assert(err == 0);
694
+
695
+ #define V(name, property) \
696
+ { \
697
+ if (stats.property != (size_t) -1) { \
698
+ js_value_t *value; \
699
+ err = js_create_int64(env, stats.property, &value); \
700
+ assert(err == 0); \
701
+ \
702
+ err = js_set_named_property(env, result, name, value); \
703
+ assert(err == 0); \
704
+ } \
705
+ }
706
+
707
+ V("heapTotal", total_heap_size)
708
+ V("heapUsed", used_heap_size)
709
+ V("external", external_memory)
710
+ #undef V
711
+
712
+ return result;
713
+ }
714
+
715
+ static js_value_t *
716
+ bare_os_freemem(js_env_t *env, js_callback_info_t *info) {
717
+ int err;
718
+
719
+ js_value_t *result;
720
+ err = js_create_int64(env, uv_get_free_memory(), &result);
721
+ assert(err == 0);
722
+
723
+ return result;
724
+ }
725
+
726
+ static js_value_t *
727
+ bare_os_totalmem(js_env_t *env, js_callback_info_t *info) {
728
+ int err;
729
+
730
+ js_value_t *result;
731
+ err = js_create_int64(env, uv_get_total_memory(), &result);
732
+ assert(err == 0);
733
+
734
+ return result;
735
+ }
736
+
737
+ static js_value_t *
738
+ bare_os_available_memory(js_env_t *env, js_callback_info_t *info) {
739
+ int err;
740
+
741
+ js_value_t *result;
742
+ err = js_create_int64(env, uv_get_available_memory(), &result);
743
+ assert(err == 0);
744
+
745
+ return result;
746
+ }
747
+
748
+ static js_value_t *
749
+ bare_os_constrained_memory(js_env_t *env, js_callback_info_t *info) {
750
+ int err;
751
+
752
+ js_value_t *result;
753
+ err = js_create_int64(env, uv_get_constrained_memory(), &result);
754
+ assert(err == 0);
755
+
756
+ return result;
757
+ }
758
+
759
+ static js_value_t *
760
+ bare_os_uptime(js_env_t *env, js_callback_info_t *info) {
761
+ int err;
762
+
763
+ double uptime;
764
+ err = uv_uptime(&uptime);
765
+ assert(err == 0);
766
+
767
+ js_value_t *result;
768
+ err = js_create_double(env, uptime, &result);
769
+ assert(err == 0);
770
+
771
+ return result;
772
+ }
773
+
774
+ static js_value_t *
775
+ bare_os_loadavg(js_env_t *env, js_callback_info_t *info) {
776
+ int err;
777
+
778
+ double *data;
779
+
780
+ js_value_t *arraybuffer;
781
+ err = js_create_arraybuffer(env, sizeof(double) * 3, (void **) &data, &arraybuffer);
782
+ assert(err == 0);
783
+
784
+ js_value_t *result;
785
+ err = js_create_typedarray(env, js_float64array, 3, arraybuffer, 0, &result);
786
+ assert(err == 0);
787
+
788
+ uv_loadavg(data);
789
+
790
+ return result;
791
+ }
792
+
793
+ static js_value_t *
794
+ bare_os_cpus(js_env_t *env, js_callback_info_t *info) {
795
+ int err;
796
+
797
+ uv_cpu_info_t *cpus;
798
+ int len;
799
+ err = uv_cpu_info(&cpus, &len);
800
+ if (err < 0) {
801
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
802
+ assert(err == 0);
803
+
804
+ return NULL;
805
+ }
806
+
807
+ js_value_t *result;
808
+ err = js_create_array_with_length(env, len, &result);
809
+ assert(err == 0);
810
+
811
+ for (uint32_t i = 0, n = len; i < n; i++) {
812
+ uv_cpu_info_t cpu = cpus[i];
813
+
814
+ js_value_t *item;
815
+ err = js_create_object(env, &item);
816
+ assert(err == 0);
817
+
818
+ err = js_set_element(env, result, i, item);
819
+ assert(err == 0);
820
+
821
+ #define V(name, type, ...) \
822
+ { \
823
+ js_value_t *val; \
824
+ err = type(env, ##__VA_ARGS__, &val); \
825
+ assert(err == 0); \
826
+ err = js_set_named_property(env, item, name, val); \
827
+ assert(err == 0); \
828
+ }
829
+
830
+ V("model", js_create_string_utf8, (const utf8_t *) cpu.model, -1)
831
+ V("speed", js_create_double, cpu.speed)
832
+ V("times", js_create_object)
833
+ #undef V
834
+
835
+ js_value_t *times;
836
+ err = js_get_named_property(env, item, "times", &times);
837
+ assert(err == 0);
838
+
839
+ #define V(name) \
840
+ { \
841
+ js_value_t *val; \
842
+ err = js_create_int64(env, cpu.cpu_times.name, &val); \
843
+ assert(err == 0); \
844
+ err = js_set_named_property(env, times, #name, val); \
845
+ assert(err == 0); \
846
+ }
847
+
848
+ V(user)
849
+ V(nice)
850
+ V(sys)
851
+ V(idle)
852
+ V(irq)
853
+ #undef V
854
+ }
855
+
856
+ uv_free_cpu_info(cpus, len);
857
+
858
+ return result;
859
+ }
860
+
861
+ static js_value_t *
862
+ bare_os_get_process_title(js_env_t *env, js_callback_info_t *info) {
863
+ int err;
864
+
865
+ char title[256];
866
+ err = uv_get_process_title(title, 256);
867
+ if (err < 0) {
868
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
869
+ assert(err == 0);
870
+
871
+ return NULL;
872
+ }
873
+
874
+ js_value_t *result;
875
+ err = js_create_string_utf8(env, (utf8_t *) title, -1, &result);
876
+ assert(err == 0);
877
+
878
+ return result;
879
+ }
880
+
881
+ static js_value_t *
882
+ bare_os_set_process_title(js_env_t *env, js_callback_info_t *info) {
883
+ int err;
884
+
885
+ size_t argc = 1;
886
+ js_value_t *argv[1];
887
+
888
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
889
+ assert(err == 0);
890
+
891
+ assert(argc == 1);
892
+
893
+ utf8_t data[256];
894
+ err = js_get_value_string_utf8(env, argv[0], data, 256, NULL);
895
+ assert(err == 0);
896
+
897
+ err = uv_set_process_title((char *) data);
898
+ assert(err == 0);
899
+
900
+ return NULL;
901
+ }
902
+
903
+ static js_value_t *
904
+ bare_os_get_priority(js_env_t *env, js_callback_info_t *info) {
905
+ int err;
906
+
907
+ size_t argc = 1;
908
+ js_value_t *argv[1];
909
+
910
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
911
+ assert(err == 0);
912
+
913
+ assert(argc == 1);
914
+
915
+ uv_pid_t pid;
916
+ err = js_get_value_int32(env, argv[0], &pid);
917
+ assert(err == 0);
918
+
919
+ int priority;
920
+ err = uv_os_getpriority(pid, &priority);
921
+ if (err < 0) {
922
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
923
+ assert(err == 0);
924
+
925
+ return NULL;
926
+ }
927
+
928
+ js_value_t *result;
929
+ err = js_create_int32(env, priority, &result);
930
+ assert(err == 0);
931
+
932
+ return result;
933
+ }
934
+
935
+ static js_value_t *
936
+ bare_os_set_priority(js_env_t *env, js_callback_info_t *info) {
937
+ int err;
938
+
939
+ size_t argc = 2;
940
+ js_value_t *argv[2];
941
+
942
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
943
+ assert(err == 0);
944
+
945
+ assert(argc == 2);
946
+
947
+ uv_pid_t pid;
948
+ err = js_get_value_int32(env, argv[0], &pid);
949
+ assert(err == 0);
950
+
951
+ int priority;
952
+ err = js_get_value_int32(env, argv[1], &priority);
953
+ assert(err == 0);
954
+
955
+ err = uv_os_setpriority(pid, priority);
956
+ if (err < 0) {
957
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
958
+ assert(err == 0);
959
+
960
+ return NULL;
961
+ }
962
+
963
+ return NULL;
964
+ }
965
+
966
+ static js_value_t *
967
+ bare_os_group_info(js_env_t *env, js_callback_info_t *info) {
968
+ int err;
969
+
970
+ size_t argc = 1;
971
+ js_value_t *argv[1];
972
+
973
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
974
+ assert(err == 0);
975
+
976
+ assert(argc == 0 || argc == 1);
977
+
978
+ bool gid_undefined;
979
+ err = js_is_undefined(env, argv[0], &gid_undefined);
980
+ assert(err == 0);
981
+
982
+ int32_t gid;
983
+ if (gid_undefined) {
984
+ #if defined(BARE_PLATFORM_WIN32)
985
+ gid = -1;
986
+ #else
987
+ gid = getegid();
988
+ #endif
989
+ } else {
990
+ err = js_get_value_int32(env, argv[0], &gid);
991
+ assert(err == 0);
992
+ }
993
+
994
+ js_value_t *result;
995
+
996
+ uv_group_t group;
997
+ err = uv_os_get_group(&group, gid);
998
+
999
+ if (err == UV_ENOTSUP) {
1000
+ err = js_get_null(env, &result);
1001
+ assert(err == 0);
1002
+
1003
+ return result;
1004
+ }
1005
+
1006
+ if (err != 0) {
1007
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
1008
+ assert(err == 0);
1009
+
1010
+ return NULL;
1011
+ }
1012
+
1013
+ err = js_create_object(env, &result);
1014
+ assert(err == 0);
1015
+
1016
+ js_value_t *groupname;
1017
+ err = js_create_string_utf8(env, (utf8_t *) group.groupname, strlen(group.groupname), &groupname);
1018
+ assert(err == 0);
1019
+
1020
+ err = js_set_named_property(env, result, "groupname", groupname);
1021
+ assert(err == 0);
1022
+
1023
+ js_value_t *grp_gid;
1024
+ err = js_create_int32(env, group.gid, &grp_gid);
1025
+ assert(err == 0);
1026
+
1027
+ err = js_set_named_property(env, result, "gid", grp_gid);
1028
+ assert(err == 0);
1029
+
1030
+ js_value_t *members;
1031
+ err = js_create_array(env, &members);
1032
+ assert(err == 0);
1033
+
1034
+ for (uint32_t i = 0; group.members[i] != NULL; i++) {
1035
+ js_value_t *member;
1036
+ err = js_create_string_utf8(env, (utf8_t *) group.members[i], strlen(group.members[i]), &member);
1037
+ assert(err == 0);
1038
+
1039
+ err = js_set_element(env, members, i, member);
1040
+ assert(err == 0);
1041
+ }
1042
+
1043
+ err = js_set_named_property(env, result, "members", members);
1044
+ assert(err == 0);
1045
+
1046
+ uv_os_free_group(&group);
1047
+
1048
+ return result;
1049
+ }
1050
+
1051
+ static js_value_t *
1052
+ bare_os_get_env_keys(js_env_t *env, js_callback_info_t *info) {
1053
+ int err;
1054
+
1055
+ uv_env_item_t *items;
1056
+ int len;
1057
+
1058
+ uv_rwlock_rdlock(&bare_os_env_lock);
1059
+
1060
+ err = uv_os_environ(&items, &len);
1061
+
1062
+ uv_rwlock_rdunlock(&bare_os_env_lock);
1063
+
1064
+ if (err < 0) {
1065
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
1066
+ assert(err == 0);
1067
+
1068
+ return NULL;
1069
+ }
1070
+
1071
+ js_value_t *result;
1072
+ err = js_create_array_with_length(env, len, &result);
1073
+ assert(err == 0);
1074
+
1075
+ for (int i = 0; i < len; i++) {
1076
+ uv_env_item_t *item = &items[i];
1077
+
1078
+ js_value_t *val;
1079
+ err = js_create_string_utf8(env, (utf8_t *) item->name, -1, &val);
1080
+ assert(err == 0);
1081
+
1082
+ err = js_set_element(env, result, i, val);
1083
+ assert(err == 0);
1084
+ }
1085
+
1086
+ uv_os_free_environ(items, len);
1087
+
1088
+ return result;
1089
+ }
1090
+
1091
+ static js_value_t *
1092
+ bare_os_get_env(js_env_t *env, js_callback_info_t *info) {
1093
+ int err;
1094
+
1095
+ size_t argc = 1;
1096
+ js_value_t *argv[1];
1097
+
1098
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1099
+ assert(err == 0);
1100
+
1101
+ assert(argc == 1);
1102
+
1103
+ size_t name_len;
1104
+ err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len);
1105
+ assert(err == 0);
1106
+
1107
+ name_len += 1 /* NULL */;
1108
+
1109
+ utf8_t *name = malloc(name_len);
1110
+ err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len);
1111
+ assert(err == 0);
1112
+
1113
+ uv_rwlock_rdlock(&bare_os_env_lock);
1114
+
1115
+ size_t value_len = 256;
1116
+ char *value = malloc(value_len);
1117
+ err = uv_os_getenv((char *) name, value, &value_len);
1118
+
1119
+ js_value_t *result;
1120
+
1121
+ if (err == UV_ENOENT) {
1122
+ err = js_get_undefined(env, &result);
1123
+ assert(err == 0);
1124
+ } else {
1125
+ if (err == UV_ENOBUFS) {
1126
+ value = realloc(value, value_len);
1127
+
1128
+ err = uv_os_getenv((char *) name, value, &value_len);
1129
+ assert(err == 0);
1130
+ } else if (err < 0) {
1131
+ uv_rwlock_rdunlock(&bare_os_env_lock);
1132
+
1133
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
1134
+ assert(err == 0);
1135
+
1136
+ free(name);
1137
+ return NULL;
1138
+ }
1139
+
1140
+ err = js_create_string_utf8(env, (utf8_t *) value, value_len, &result);
1141
+ assert(err == 0);
1142
+ }
1143
+
1144
+ uv_rwlock_rdunlock(&bare_os_env_lock);
1145
+
1146
+ free(name);
1147
+ free(value);
1148
+
1149
+ return result;
1150
+ }
1151
+
1152
+ static js_value_t *
1153
+ bare_os_has_env(js_env_t *env, js_callback_info_t *info) {
1154
+ int err;
1155
+
1156
+ size_t argc = 1;
1157
+ js_value_t *argv[1];
1158
+
1159
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1160
+ assert(err == 0);
1161
+
1162
+ assert(argc == 1);
1163
+
1164
+ size_t name_len;
1165
+ err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len);
1166
+ assert(err == 0);
1167
+
1168
+ utf8_t *name = malloc(++name_len);
1169
+ err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len);
1170
+ assert(err == 0);
1171
+
1172
+ uv_rwlock_rdlock(&bare_os_env_lock);
1173
+
1174
+ size_t value_len = 1;
1175
+ char value[1];
1176
+ err = uv_os_getenv((char *) name, value, &value_len);
1177
+
1178
+ uv_rwlock_rdunlock(&bare_os_env_lock);
1179
+
1180
+ if (err != 0 && err != UV_ENOENT && err != UV_ENOBUFS) {
1181
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
1182
+ assert(err == 0);
1183
+
1184
+ free(name);
1185
+ return NULL;
1186
+ }
1187
+
1188
+ free(name);
1189
+
1190
+ js_value_t *result;
1191
+ err = js_get_boolean(env, err != UV_ENOENT, &result);
1192
+ assert(err == 0);
1193
+
1194
+ return result;
1195
+ }
1196
+
1197
+ static js_value_t *
1198
+ bare_os_set_env(js_env_t *env, js_callback_info_t *info) {
1199
+ int err;
1200
+
1201
+ size_t argc = 2;
1202
+ js_value_t *argv[2];
1203
+
1204
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1205
+ assert(err == 0);
1206
+
1207
+ assert(argc == 2);
1208
+
1209
+ size_t name_len;
1210
+ err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len);
1211
+ assert(err == 0);
1212
+
1213
+ utf8_t *name = malloc(++name_len);
1214
+ err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len);
1215
+ assert(err == 0);
1216
+
1217
+ size_t value_len;
1218
+ err = js_get_value_string_utf8(env, argv[1], NULL, 0, &value_len);
1219
+ assert(err == 0);
1220
+
1221
+ utf8_t *value = malloc(++value_len);
1222
+ err = js_get_value_string_utf8(env, argv[1], value, value_len, &value_len);
1223
+ assert(err == 0);
1224
+
1225
+ uv_rwlock_wrlock(&bare_os_env_lock);
1226
+
1227
+ err = uv_os_setenv((char *) name, (char *) value);
1228
+
1229
+ uv_rwlock_wrunlock(&bare_os_env_lock);
1230
+
1231
+ if (err < 0) {
1232
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
1233
+ assert(err == 0);
1234
+
1235
+ free(name);
1236
+ free(value);
1237
+ return NULL;
1238
+ }
1239
+
1240
+ free(name);
1241
+ free(value);
1242
+
1243
+ return NULL;
1244
+ }
1245
+
1246
+ static js_value_t *
1247
+ bare_os_unset_env(js_env_t *env, js_callback_info_t *info) {
1248
+ int err;
1249
+
1250
+ size_t argc = 1;
1251
+ js_value_t *argv[1];
1252
+
1253
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
1254
+ assert(err == 0);
1255
+
1256
+ assert(argc == 1);
1257
+
1258
+ size_t name_len;
1259
+ err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len);
1260
+ assert(err == 0);
1261
+
1262
+ utf8_t *name = malloc(++name_len);
1263
+ err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len);
1264
+ assert(err == 0);
1265
+
1266
+ uv_rwlock_wrlock(&bare_os_env_lock);
1267
+
1268
+ err = uv_os_unsetenv((char *) name);
1269
+
1270
+ uv_rwlock_wrunlock(&bare_os_env_lock);
1271
+
1272
+ if (err < 0) {
1273
+ err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
1274
+ assert(err == 0);
1275
+
1276
+ free(name);
1277
+ return NULL;
1278
+ }
1279
+
1280
+ free(name);
1281
+
1282
+ return NULL;
1283
+ }
1284
+
1285
+ static js_value_t *
1286
+ bare_os_exports(js_env_t *env, js_value_t *exports) {
1287
+ uv_once(&bare_os_env_lock_guard, bare_os__on_env_lock_init);
1288
+
1289
+ int err;
1290
+
1291
+ #define V(name, str) \
1292
+ { \
1293
+ js_value_t *val; \
1294
+ err = js_create_string_utf8(env, (utf8_t *) str, -1, &val); \
1295
+ assert(err == 0); \
1296
+ err = js_set_named_property(env, exports, name, val); \
1297
+ assert(err == 0); \
1298
+ }
1299
+
1300
+ V("platform", BARE_PLATFORM)
1301
+ V("arch", BARE_ARCH)
1302
+ #undef V
1303
+
1304
+ #define V(name, fn) \
1305
+ { \
1306
+ js_value_t *val; \
1307
+ err = js_create_function(env, name, -1, fn, NULL, &val); \
1308
+ assert(err == 0); \
1309
+ err = js_set_named_property(env, exports, name, val); \
1310
+ assert(err == 0); \
1311
+ }
1312
+
1313
+ V("type", bare_os_type)
1314
+ V("version", bare_os_version)
1315
+ V("release", bare_os_release)
1316
+ V("machine", bare_os_machine)
1317
+ V("execPath", bare_os_exec_path)
1318
+ V("pid", bare_os_pid)
1319
+ V("ppid", bare_os_ppid)
1320
+ V("cwd", bare_os_cwd)
1321
+ V("chdir", bare_os_chdir)
1322
+ V("tmpdir", bare_os_tmpdir)
1323
+ V("homedir", bare_os_homedir)
1324
+ V("hostname", bare_os_hostname)
1325
+ V("kill", bare_os_kill)
1326
+ V("availableParallelism", bare_os_available_parallelism)
1327
+ V("cpuUsage", bare_os_cpu_usage)
1328
+ V("threadCpuUsage", bare_os_cpu_usage_thread)
1329
+ V("resourceUsage", bare_os_resource_usage)
1330
+ V("memoryUsage", bare_os_memory_usage)
1331
+ V("freemem", bare_os_freemem)
1332
+ V("totalmem", bare_os_totalmem)
1333
+ V("availableMemory", bare_os_available_memory)
1334
+ V("constrainedMemory", bare_os_constrained_memory)
1335
+ V("uptime", bare_os_uptime)
1336
+ V("loadavg", bare_os_loadavg)
1337
+ V("cpus", bare_os_cpus)
1338
+ V("getProcessTitle", bare_os_get_process_title)
1339
+ V("setProcessTitle", bare_os_set_process_title)
1340
+ V("getPriority", bare_os_get_priority)
1341
+ V("setPriority", bare_os_set_priority)
1342
+ V("getEnvKeys", bare_os_get_env_keys)
1343
+ V("getEnv", bare_os_get_env)
1344
+ V("hasEnv", bare_os_get_env)
1345
+ V("setEnv", bare_os_set_env)
1346
+ V("unsetEnv", bare_os_unset_env)
1347
+ V("userInfo", bare_os_user_info)
1348
+ V("networkInterfaces", bare_os_network_interfaces)
1349
+ V("groupInfo", bare_os_group_info)
1350
+ #undef V
1351
+
1352
+ const union {
1353
+ uint8_t u8[2];
1354
+ uint16_t u16;
1355
+ } byte_order = {{1, 0}};
1356
+
1357
+ js_value_t *is_little_endian;
1358
+ err = js_get_boolean(env, byte_order.u16 == 1, &is_little_endian);
1359
+ assert(err == 0);
1360
+
1361
+ err = js_set_named_property(env, exports, "isLittleEndian", is_little_endian);
1362
+ assert(err == 0);
1363
+
1364
+ js_value_t *signals;
1365
+ err = js_create_object(env, &signals);
1366
+ assert(err == 0);
1367
+
1368
+ err = js_set_named_property(env, exports, "signals", signals);
1369
+ assert(err == 0);
1370
+
1371
+ #define V(name) \
1372
+ { \
1373
+ js_value_t *val; \
1374
+ err = js_create_uint32(env, name, &val); \
1375
+ assert(err == 0); \
1376
+ err = js_set_named_property(env, signals, #name, val); \
1377
+ assert(err == 0); \
1378
+ }
1379
+
1380
+ #ifdef SIGHUP
1381
+ V(SIGHUP);
1382
+ #endif
1383
+ #ifdef SIGINT
1384
+ V(SIGINT);
1385
+ #endif
1386
+ #ifdef SIGQUIT
1387
+ V(SIGQUIT);
1388
+ #endif
1389
+ #ifdef SIGILL
1390
+ V(SIGILL);
1391
+ #endif
1392
+ #ifdef SIGTRAP
1393
+ V(SIGTRAP);
1394
+ #endif
1395
+ #ifdef SIGABRT
1396
+ V(SIGABRT);
1397
+ #endif
1398
+ #ifdef SIGIOT
1399
+ V(SIGIOT);
1400
+ #endif
1401
+ #ifdef SIGBUS
1402
+ V(SIGBUS);
1403
+ #endif
1404
+ #ifdef SIGFPE
1405
+ V(SIGFPE);
1406
+ #endif
1407
+ #ifdef SIGKILL
1408
+ V(SIGKILL);
1409
+ #endif
1410
+ #ifdef SIGUSR1
1411
+ V(SIGUSR1);
1412
+ #endif
1413
+ #ifdef SIGSEGV
1414
+ V(SIGSEGV);
1415
+ #endif
1416
+ #ifdef SIGUSR2
1417
+ V(SIGUSR2);
1418
+ #endif
1419
+ #ifdef SIGPIPE
1420
+ V(SIGPIPE);
1421
+ #endif
1422
+ #ifdef SIGALRM
1423
+ V(SIGALRM);
1424
+ #endif
1425
+ #ifdef SIGTERM
1426
+ V(SIGTERM);
1427
+ #endif
1428
+ #ifdef SIGCHLD
1429
+ V(SIGCHLD);
1430
+ #endif
1431
+ #ifdef SIGSTKFLT
1432
+ V(SIGSTKFLT);
1433
+ #endif
1434
+ #ifdef SIGCONT
1435
+ V(SIGCONT);
1436
+ #endif
1437
+ #ifdef SIGSTOP
1438
+ V(SIGSTOP);
1439
+ #endif
1440
+ #ifdef SIGTSTP
1441
+ V(SIGTSTP);
1442
+ #endif
1443
+ #ifdef SIGBREAK
1444
+ V(SIGBREAK);
1445
+ #endif
1446
+ #ifdef SIGTTIN
1447
+ V(SIGTTIN);
1448
+ #endif
1449
+ #ifdef SIGTTOU
1450
+ V(SIGTTOU);
1451
+ #endif
1452
+ #ifdef SIGURG
1453
+ V(SIGURG);
1454
+ #endif
1455
+ #ifdef SIGXCPU
1456
+ V(SIGXCPU);
1457
+ #endif
1458
+ #ifdef SIGXFSZ
1459
+ V(SIGXFSZ);
1460
+ #endif
1461
+ #ifdef SIGVTALRM
1462
+ V(SIGVTALRM);
1463
+ #endif
1464
+ #ifdef SIGPROF
1465
+ V(SIGPROF);
1466
+ #endif
1467
+ #ifdef SIGWINCH
1468
+ V(SIGWINCH);
1469
+ #endif
1470
+ #ifdef SIGIO
1471
+ V(SIGIO);
1472
+ #endif
1473
+ #ifdef SIGPOLL
1474
+ V(SIGPOLL);
1475
+ #endif
1476
+ #ifdef SIGLOST
1477
+ V(SIGLOST);
1478
+ #endif
1479
+ #ifdef SIGPWR
1480
+ V(SIGPWR);
1481
+ #endif
1482
+ #ifdef SIGINFO
1483
+ V(SIGINFO);
1484
+ #endif
1485
+ #ifdef SIGSYS
1486
+ V(SIGSYS);
1487
+ #endif
1488
+ #ifdef SIGUNUSED
1489
+ V(SIGUNUSED);
1490
+ #endif
1491
+ #undef V
1492
+
1493
+ js_value_t *errnos;
1494
+ err = js_create_object(env, &errnos);
1495
+ assert(err == 0);
1496
+
1497
+ err = js_set_named_property(env, exports, "errnos", errnos);
1498
+ assert(err == 0);
1499
+
1500
+ #define V(name, msg) \
1501
+ { \
1502
+ js_value_t *val; \
1503
+ err = js_create_int32(env, UV_##name, &val); \
1504
+ assert(err == 0); \
1505
+ err = js_set_named_property(env, errnos, #name, val); \
1506
+ assert(err == 0); \
1507
+ }
1508
+
1509
+ UV_ERRNO_MAP(V);
1510
+ #undef V
1511
+
1512
+ js_value_t *priority;
1513
+ err = js_create_object(env, &priority);
1514
+ assert(err == 0);
1515
+
1516
+ err = js_set_named_property(env, exports, "priority", priority);
1517
+ assert(err == 0);
1518
+
1519
+ #define V(name) \
1520
+ { \
1521
+ js_value_t *val; \
1522
+ err = js_create_int32(env, UV_##name, &val); \
1523
+ assert(err == 0); \
1524
+ err = js_set_named_property(env, priority, #name, val); \
1525
+ assert(err == 0); \
1526
+ }
1527
+
1528
+ V(PRIORITY_LOW);
1529
+ V(PRIORITY_BELOW_NORMAL);
1530
+ V(PRIORITY_NORMAL);
1531
+ V(PRIORITY_ABOVE_NORMAL);
1532
+ V(PRIORITY_HIGH);
1533
+ V(PRIORITY_HIGHEST);
1534
+
1535
+ return exports;
1536
+ }
1537
+
1538
+ BARE_MODULE(bare_os, bare_os_exports)
node_modules/bare-os/binding.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = require.addon()
node_modules/bare-os/index.d.ts ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import constants from './lib/constants'
2
+ import errors from './lib/errors'
3
+
4
+ export { constants, errors }
5
+
6
+ export const EOL: '\r\n' | '\n'
7
+
8
+ export const devNull: '\\\\.\\nul' | '/dev/null'
9
+
10
+ export function platform(): 'android' | 'darwin' | 'ios' | 'linux' | 'win32'
11
+
12
+ export function arch(): 'arm' | 'arm64' | 'ia32' | 'x64'
13
+
14
+ export function type(): string
15
+
16
+ export function version(): string
17
+
18
+ export function release(): string
19
+
20
+ export function machine(): string
21
+
22
+ export function execPath(): string
23
+
24
+ export function pid(): number
25
+
26
+ export function ppid(): number
27
+
28
+ export function cwd(): string
29
+
30
+ export function chdir(dir: string): string
31
+
32
+ export function tmpdir(): string
33
+
34
+ export function homedir(): string
35
+
36
+ export function hostname(): string
37
+
38
+ export interface NetworkInterface {
39
+ address: string
40
+ netmask: string
41
+ family: 'IPv4' | 'IPv6'
42
+ cidr: string
43
+ mac: string
44
+ internal: boolean
45
+ scopeid?: number
46
+ }
47
+
48
+ export function networkInterfaces(): Record<string, NetworkInterface[]>
49
+
50
+ export function kill(pid: number, signal?: string | number): void
51
+
52
+ export interface UserInfo {
53
+ uid: number
54
+ gid: number
55
+ username: string
56
+ homedir: string
57
+ shell: string | null
58
+ }
59
+
60
+ export function userInfo(uid?: number): UserInfo
61
+
62
+ export interface GroupInfo {
63
+ groupname: string
64
+ gid: number
65
+ members: string[]
66
+ }
67
+
68
+ export function groupInfo(gid?: number): GroupInfo | null
69
+
70
+ export function endianness(): 'LE' | 'BE'
71
+
72
+ export function availableParallelism(): number
73
+
74
+ export interface CpuUsage {
75
+ user: number
76
+ system: number
77
+ }
78
+
79
+ export function cpuUsage(previous?: CpuUsage): CpuUsage
80
+
81
+ export function threadCpuUsage(previous?: CpuUsage): CpuUsage
82
+
83
+ export function resourceUsage(): {
84
+ userCPUTime: number
85
+ systemCPUTime: number
86
+ maxRSS: number
87
+ sharedMemorySize: number
88
+ unsharedDataSize: number
89
+ unsharedStackSize: number
90
+ minorPageFault: number
91
+ majorPageFault: number
92
+ swappedOut: number
93
+ fsRead: number
94
+ fsWrite: number
95
+ ipcSent: number
96
+ ipcReceived: number
97
+ signalsCount: number
98
+ voluntaryContextSwitches: number
99
+ involuntaryContextSwitches: number
100
+ }
101
+
102
+ export function memoryUsage(): {
103
+ rss: number
104
+ heapTotal: number
105
+ heapUsed: number
106
+ external: number
107
+ }
108
+
109
+ export function freemem(): number
110
+
111
+ export function totalmem(): number
112
+
113
+ export function availableMemory(): number
114
+
115
+ export function constrainedMemory(): number
116
+
117
+ export function uptime(): number
118
+
119
+ export function loadavg(): ArrayLike<number>
120
+
121
+ export function cpus(): {
122
+ model: string
123
+ speed: number
124
+ times: {
125
+ user: number
126
+ nice: number
127
+ sys: number
128
+ idle: number
129
+ irq: number
130
+ }
131
+ }[]
132
+
133
+ export function getProcessTitle(): string
134
+
135
+ export function setProcessTitle(title: unknown): void
136
+
137
+ export function getPriority(pid?: number): number
138
+
139
+ export function setPriority(priority: number): void
140
+ export function setPriority(pid: number, priority: number): void
141
+
142
+ export function getEnvKeys(): string[]
143
+
144
+ export function getEnv(name: string): string | undefined
145
+
146
+ export function hasEnv(name: string): boolean
147
+
148
+ export function setEnv(name: string, value: string): void
149
+
150
+ export function unsetEnv(name: string): void
node_modules/bare-os/index.js ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const binding = require('./binding')
2
+ const errors = require('./lib/errors')
3
+ const constants = require('./lib/constants')
4
+
5
+ exports.constants = constants
6
+ exports.errors = errors
7
+
8
+ exports.EOL = binding.platform === 'win32' ? '\r\n' : '\n'
9
+
10
+ exports.devNull = binding.platform === 'win32' ? '\\\\.\\nul' : '/dev/null'
11
+
12
+ exports.platform = function platform() {
13
+ return binding.platform
14
+ }
15
+
16
+ exports.arch = function arch() {
17
+ return binding.arch
18
+ }
19
+
20
+ exports.type = binding.type
21
+ exports.version = binding.version
22
+ exports.release = binding.release
23
+ exports.machine = binding.machine
24
+ exports.execPath = binding.execPath
25
+ exports.pid = binding.pid
26
+ exports.ppid = binding.ppid
27
+ exports.cwd = binding.cwd
28
+ exports.chdir = binding.chdir
29
+ exports.tmpdir = binding.tmpdir
30
+ exports.homedir = binding.homedir
31
+ exports.hostname = binding.hostname
32
+ exports.userInfo = binding.userInfo
33
+ exports.groupInfo = binding.groupInfo
34
+
35
+ exports.networkInterfaces = function networkInterfaces() {
36
+ const result = {}
37
+
38
+ for (const entry of binding.networkInterfaces()) {
39
+ const { name, ...properties } = entry
40
+
41
+ if (result[name]) result[name].push(properties)
42
+ else result[name] = [properties]
43
+ }
44
+
45
+ return result
46
+ }
47
+
48
+ exports.kill = function kill(pid, signal = constants.signals.SIGTERM) {
49
+ if (typeof signal === 'string') {
50
+ if (signal in constants.signals === false) {
51
+ throw errors.UNKNOWN_SIGNAL('Unknown signal: ' + signal)
52
+ }
53
+
54
+ signal = constants.signals[signal]
55
+ }
56
+
57
+ binding.kill(pid, signal)
58
+ }
59
+
60
+ exports.endianness = function endianness() {
61
+ return binding.isLittleEndian ? 'LE' : 'BE'
62
+ }
63
+
64
+ exports.availableParallelism = binding.availableParallelism
65
+
66
+ exports.cpuUsage = function cpuUsage(previous) {
67
+ const current = binding.cpuUsage()
68
+
69
+ if (previous) {
70
+ return {
71
+ user: current.user - previous.user,
72
+ system: current.system - previous.system
73
+ }
74
+ }
75
+
76
+ return current
77
+ }
78
+
79
+ exports.threadCpuUsage = function threadCpuUsage(previous) {
80
+ const current = binding.threadCpuUsage()
81
+
82
+ if (previous) {
83
+ return {
84
+ user: current.user - previous.user,
85
+ system: current.system - previous.system
86
+ }
87
+ }
88
+
89
+ return current
90
+ }
91
+
92
+ exports.resourceUsage = binding.resourceUsage
93
+ exports.memoryUsage = binding.memoryUsage
94
+ exports.freemem = binding.freemem
95
+ exports.totalmem = binding.totalmem
96
+ exports.availableMemory = binding.availableMemory
97
+ exports.constrainedMemory = binding.constrainedMemory
98
+ exports.uptime = binding.uptime
99
+ exports.loadavg = binding.loadavg
100
+ exports.cpus = binding.cpus
101
+
102
+ exports.getProcessTitle = binding.getProcessTitle
103
+
104
+ exports.setProcessTitle = function setProcessTitle(title) {
105
+ if (typeof title !== 'string') title = title.toString()
106
+
107
+ if (title.length >= 256) {
108
+ throw errors.TITLE_OVERFLOW('Process title is too long')
109
+ }
110
+
111
+ binding.setProcessTitle(title)
112
+ }
113
+
114
+ exports.getPriority = function getPriority(pid = 0) {
115
+ return binding.getPriority(pid)
116
+ }
117
+
118
+ exports.setPriority = function setPriority(pid, priority) {
119
+ if (priority === undefined) {
120
+ priority = pid
121
+ pid = 0
122
+ }
123
+
124
+ binding.setPriority(pid, priority)
125
+ }
126
+
127
+ exports.getEnvKeys = binding.getEnvKeys
128
+ exports.getEnv = binding.getEnv
129
+ exports.hasEnv = binding.hasEnv
130
+ exports.setEnv = binding.setEnv
131
+ exports.unsetEnv = binding.unsetEnv
node_modules/bare-os/lib/constants.d.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ declare const constants: {
2
+ signals: Record<string, number>
3
+ errnos: Record<string, number>
4
+ priority: Record<string, number>
5
+ }
6
+
7
+ export = constants
node_modules/bare-os/lib/constants.js ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ const binding = require('../binding')
2
+
3
+ module.exports = {
4
+ signals: binding.signals,
5
+ errnos: binding.errnos,
6
+ priority: binding.priority
7
+ }
node_modules/bare-os/lib/errors.d.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ declare class OSError extends Error {
2
+ readonly code: string
3
+ }
4
+
5
+ export = OSError
node_modules/bare-os/lib/errors.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = class OSError extends Error {
2
+ constructor(msg, fn = OSError, code = fn.name) {
3
+ super(`${code}: ${msg}`)
4
+ this.code = code
5
+
6
+ if (Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, fn)
8
+ }
9
+ }
10
+
11
+ get name() {
12
+ return 'OSError'
13
+ }
14
+
15
+ static UNKNOWN_SIGNAL(msg) {
16
+ return new OSError(msg, OSError.UNKNOWN_SIGNAL)
17
+ }
18
+
19
+ static TITLE_OVERFLOW(msg) {
20
+ return new OSError(msg, OSError.TITLE_OVERFLOW)
21
+ }
22
+ }
node_modules/bare-os/package.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "bare-os",
3
+ "version": "3.9.1",
4
+ "description": "Operating system utilities for Bare",
5
+ "exports": {
6
+ "./package": "./package.json",
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ },
11
+ "./constants": {
12
+ "types": "./lib/constants.d.ts",
13
+ "default": "./lib/constants.js"
14
+ },
15
+ "./errors": {
16
+ "types": "./lib/errors.d.ts",
17
+ "default": "./lib/errors.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "index.js",
22
+ "index.d.ts",
23
+ "binding.c",
24
+ "binding.js",
25
+ "CMakeLists.txt",
26
+ "lib",
27
+ "prebuilds"
28
+ ],
29
+ "addon": true,
30
+ "scripts": {
31
+ "format": "prettier --write . && lunte --fix",
32
+ "lint": "prettier --check . && lunte",
33
+ "test": "brittle-bare --coverage test.js"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/holepunchto/bare-os.git"
38
+ },
39
+ "author": "Holepunch",
40
+ "license": "Apache-2.0",
41
+ "bugs": {
42
+ "url": "https://github.com/holepunchto/bare-os/issues"
43
+ },
44
+ "homepage": "https://github.com/holepunchto/bare-os#readme",
45
+ "engines": {
46
+ "bare": ">=1.14.0"
47
+ },
48
+ "devDependencies": {
49
+ "brittle": "^3.1.1",
50
+ "cmake-bare": "^1.1.6",
51
+ "lunte": "^1.6.0",
52
+ "prettier": "^3.4.2",
53
+ "prettier-config-holepunch": "^2.0.0"
54
+ }
55
+ }
node_modules/bare-os/prebuilds/android-arm/bare-os.bare ADDED
Binary file (34.3 kB). View file
 
node_modules/bare-os/prebuilds/android-arm64/bare-os.bare ADDED
Binary file (39.6 kB). View file
 
node_modules/bare-os/prebuilds/android-ia32/bare-os.bare ADDED
Binary file (34.4 kB). View file
 
node_modules/bare-os/prebuilds/android-x64/bare-os.bare ADDED
Binary file (38.2 kB). View file
 
node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare ADDED
Binary file (73.3 kB). View file