memfs 4.55.0 → 4.56.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/README.md +75 -2
  2. package/lib/fsa/index.d.ts +1 -33
  3. package/lib/fsa/index.js +1 -39
  4. package/lib/fsa/index.js.map +1 -1
  5. package/lib/fsa-to-node/index.d.ts +1 -2
  6. package/lib/fsa-to-node/index.js +2 -5
  7. package/lib/fsa-to-node/index.js.map +1 -1
  8. package/lib/index.d.ts +6 -7
  9. package/lib/index.js +10 -14
  10. package/lib/index.js.map +1 -1
  11. package/lib/node-to-fsa/index.d.ts +1 -7
  12. package/lib/node-to-fsa/index.js +1 -10
  13. package/lib/node-to-fsa/index.js.map +1 -1
  14. package/package.json +9 -3
  15. package/lib/constants.d.ts +0 -67
  16. package/lib/constants.js +0 -54
  17. package/lib/constants.js.map +0 -1
  18. package/lib/consts/AMODE.d.ts +0 -9
  19. package/lib/consts/AMODE.js +0 -3
  20. package/lib/consts/AMODE.js.map +0 -1
  21. package/lib/consts/FLAG.d.ts +0 -53
  22. package/lib/consts/FLAG.js +0 -36
  23. package/lib/consts/FLAG.js.map +0 -1
  24. package/lib/core/File.d.ts +0 -39
  25. package/lib/core/File.js +0 -72
  26. package/lib/core/File.js.map +0 -1
  27. package/lib/core/Link.d.ts +0 -38
  28. package/lib/core/Link.js +0 -105
  29. package/lib/core/Link.js.map +0 -1
  30. package/lib/core/Node.d.ts +0 -85
  31. package/lib/core/Node.js +0 -287
  32. package/lib/core/Node.js.map +0 -1
  33. package/lib/core/Superblock.d.ts +0 -92
  34. package/lib/core/Superblock.js +0 -689
  35. package/lib/core/Superblock.js.map +0 -1
  36. package/lib/core/constants.d.ts +0 -15
  37. package/lib/core/constants.js +0 -3
  38. package/lib/core/constants.js.map +0 -1
  39. package/lib/core/index.d.ts +0 -6
  40. package/lib/core/index.js +0 -15
  41. package/lib/core/index.js.map +0 -1
  42. package/lib/core/json.d.ts +0 -9
  43. package/lib/core/json.js +0 -35
  44. package/lib/core/json.js.map +0 -1
  45. package/lib/core/result.d.ts +0 -11
  46. package/lib/core/result.js +0 -11
  47. package/lib/core/result.js.map +0 -1
  48. package/lib/core/types.d.ts +0 -8
  49. package/lib/core/types.js +0 -3
  50. package/lib/core/types.js.map +0 -1
  51. package/lib/core/util.d.ts +0 -12
  52. package/lib/core/util.js +0 -74
  53. package/lib/core/util.js.map +0 -1
  54. package/lib/encoding.d.ts +0 -6
  55. package/lib/encoding.js +0 -20
  56. package/lib/encoding.js.map +0 -1
  57. package/lib/fsa/CoreFileSystemDirectoryHandle.d.ts +0 -73
  58. package/lib/fsa/CoreFileSystemDirectoryHandle.js +0 -265
  59. package/lib/fsa/CoreFileSystemDirectoryHandle.js.map +0 -1
  60. package/lib/fsa/CoreFileSystemFileHandle.d.ts +0 -25
  61. package/lib/fsa/CoreFileSystemFileHandle.js +0 -75
  62. package/lib/fsa/CoreFileSystemFileHandle.js.map +0 -1
  63. package/lib/fsa/CoreFileSystemHandle.d.ts +0 -34
  64. package/lib/fsa/CoreFileSystemHandle.js +0 -53
  65. package/lib/fsa/CoreFileSystemHandle.js.map +0 -1
  66. package/lib/fsa/CoreFileSystemObserver.d.ts +0 -10
  67. package/lib/fsa/CoreFileSystemObserver.js +0 -18
  68. package/lib/fsa/CoreFileSystemObserver.js.map +0 -1
  69. package/lib/fsa/CoreFileSystemSyncAccessHandle.d.ts +0 -38
  70. package/lib/fsa/CoreFileSystemSyncAccessHandle.js +0 -123
  71. package/lib/fsa/CoreFileSystemSyncAccessHandle.js.map +0 -1
  72. package/lib/fsa/CoreFileSystemWritableFileStream.d.ts +0 -32
  73. package/lib/fsa/CoreFileSystemWritableFileStream.js +0 -163
  74. package/lib/fsa/CoreFileSystemWritableFileStream.js.map +0 -1
  75. package/lib/fsa/CorePermissionStatus.d.ts +0 -9
  76. package/lib/fsa/CorePermissionStatus.js +0 -14
  77. package/lib/fsa/CorePermissionStatus.js.map +0 -1
  78. package/lib/fsa/FileLockManager.d.ts +0 -7
  79. package/lib/fsa/FileLockManager.js +0 -26
  80. package/lib/fsa/FileLockManager.js.map +0 -1
  81. package/lib/fsa/types.d.ts +0 -182
  82. package/lib/fsa/types.js +0 -3
  83. package/lib/fsa/types.js.map +0 -1
  84. package/lib/fsa/util.d.ts +0 -12
  85. package/lib/fsa/util.js +0 -45
  86. package/lib/fsa/util.js.map +0 -1
  87. package/lib/fsa-to-node/FsaNodeCore.d.ts +0 -33
  88. package/lib/fsa-to-node/FsaNodeCore.js +0 -191
  89. package/lib/fsa-to-node/FsaNodeCore.js.map +0 -1
  90. package/lib/fsa-to-node/FsaNodeDirent.d.ts +0 -19
  91. package/lib/fsa-to-node/FsaNodeDirent.js +0 -39
  92. package/lib/fsa-to-node/FsaNodeDirent.js.map +0 -1
  93. package/lib/fsa-to-node/FsaNodeFs.d.ts +0 -187
  94. package/lib/fsa-to-node/FsaNodeFs.js +0 -831
  95. package/lib/fsa-to-node/FsaNodeFs.js.map +0 -1
  96. package/lib/fsa-to-node/FsaNodeFsOpenFile.d.ts +0 -24
  97. package/lib/fsa-to-node/FsaNodeFsOpenFile.js +0 -37
  98. package/lib/fsa-to-node/FsaNodeFsOpenFile.js.map +0 -1
  99. package/lib/fsa-to-node/FsaNodeReadStream.d.ts +0 -23
  100. package/lib/fsa-to-node/FsaNodeReadStream.js +0 -92
  101. package/lib/fsa-to-node/FsaNodeReadStream.js.map +0 -1
  102. package/lib/fsa-to-node/FsaNodeStats.d.ts +0 -30
  103. package/lib/fsa-to-node/FsaNodeStats.js +0 -53
  104. package/lib/fsa-to-node/FsaNodeStats.js.map +0 -1
  105. package/lib/fsa-to-node/FsaNodeWriteStream.d.ts +0 -47
  106. package/lib/fsa-to-node/FsaNodeWriteStream.js +0 -150
  107. package/lib/fsa-to-node/FsaNodeWriteStream.js.map +0 -1
  108. package/lib/fsa-to-node/constants.d.ts +0 -3
  109. package/lib/fsa-to-node/constants.js +0 -3
  110. package/lib/fsa-to-node/constants.js.map +0 -1
  111. package/lib/fsa-to-node/json.d.ts +0 -2
  112. package/lib/fsa-to-node/json.js +0 -7
  113. package/lib/fsa-to-node/json.js.map +0 -1
  114. package/lib/fsa-to-node/types.d.ts +0 -37
  115. package/lib/fsa-to-node/types.js +0 -3
  116. package/lib/fsa-to-node/types.js.map +0 -1
  117. package/lib/fsa-to-node/util.d.ts +0 -4
  118. package/lib/fsa-to-node/util.js +0 -34
  119. package/lib/fsa-to-node/util.js.map +0 -1
  120. package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.d.ts +0 -10
  121. package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.js +0 -62
  122. package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.js.map +0 -1
  123. package/lib/fsa-to-node/worker/FsaNodeSyncWorker.d.ts +0 -20
  124. package/lib/fsa-to-node/worker/FsaNodeSyncWorker.js +0 -178
  125. package/lib/fsa-to-node/worker/FsaNodeSyncWorker.js.map +0 -1
  126. package/lib/fsa-to-node/worker/SyncMessenger.d.ts +0 -24
  127. package/lib/fsa-to-node/worker/SyncMessenger.js +0 -72
  128. package/lib/fsa-to-node/worker/SyncMessenger.js.map +0 -1
  129. package/lib/fsa-to-node/worker/constants.d.ts +0 -8
  130. package/lib/fsa-to-node/worker/constants.js +0 -3
  131. package/lib/fsa-to-node/worker/constants.js.map +0 -1
  132. package/lib/fsa-to-node/worker/types.d.ts +0 -17
  133. package/lib/fsa-to-node/worker/types.js +0 -3
  134. package/lib/fsa-to-node/worker/types.js.map +0 -1
  135. package/lib/node/Dir.d.ts +0 -26
  136. package/lib/node/Dir.js +0 -186
  137. package/lib/node/Dir.js.map +0 -1
  138. package/lib/node/Dirent.d.ts +0 -26
  139. package/lib/node/Dirent.js +0 -57
  140. package/lib/node/Dirent.js.map +0 -1
  141. package/lib/node/FileHandle.d.ts +0 -52
  142. package/lib/node/FileHandle.js +0 -189
  143. package/lib/node/FileHandle.js.map +0 -1
  144. package/lib/node/FsPromises.d.ts +0 -91
  145. package/lib/node/FsPromises.js +0 -161
  146. package/lib/node/FsPromises.js.map +0 -1
  147. package/lib/node/StatFs.d.ts +0 -19
  148. package/lib/node/StatFs.js +0 -34
  149. package/lib/node/StatFs.js.map +0 -1
  150. package/lib/node/Stats.d.ts +0 -41
  151. package/lib/node/Stats.js +0 -72
  152. package/lib/node/Stats.js.map +0 -1
  153. package/lib/node/constants.d.ts +0 -41
  154. package/lib/node/constants.js +0 -57
  155. package/lib/node/constants.js.map +0 -1
  156. package/lib/node/glob.d.ts +0 -5
  157. package/lib/node/glob.js +0 -94
  158. package/lib/node/glob.js.map +0 -1
  159. package/lib/node/lists/fsCallbackApiList.d.ts +0 -2
  160. package/lib/node/lists/fsCallbackApiList.js +0 -55
  161. package/lib/node/lists/fsCallbackApiList.js.map +0 -1
  162. package/lib/node/lists/fsCommonObjectsList.d.ts +0 -2
  163. package/lib/node/lists/fsCommonObjectsList.js +0 -19
  164. package/lib/node/lists/fsCommonObjectsList.js.map +0 -1
  165. package/lib/node/lists/fsSynchronousApiList.d.ts +0 -2
  166. package/lib/node/lists/fsSynchronousApiList.js +0 -49
  167. package/lib/node/lists/fsSynchronousApiList.js.map +0 -1
  168. package/lib/node/options.d.ts +0 -27
  169. package/lib/node/options.js +0 -112
  170. package/lib/node/options.js.map +0 -1
  171. package/lib/node/types/FsCallbackApi.d.ts +0 -143
  172. package/lib/node/types/FsCallbackApi.js +0 -3
  173. package/lib/node/types/FsCallbackApi.js.map +0 -1
  174. package/lib/node/types/FsCommonObjects.d.ts +0 -17
  175. package/lib/node/types/FsCommonObjects.js +0 -3
  176. package/lib/node/types/FsCommonObjects.js.map +0 -1
  177. package/lib/node/types/FsPromisesApi.d.ts +0 -41
  178. package/lib/node/types/FsPromisesApi.js +0 -3
  179. package/lib/node/types/FsPromisesApi.js.map +0 -1
  180. package/lib/node/types/FsSynchronousApi.d.ts +0 -114
  181. package/lib/node/types/FsSynchronousApi.js +0 -3
  182. package/lib/node/types/FsSynchronousApi.js.map +0 -1
  183. package/lib/node/types/index.d.ts +0 -7
  184. package/lib/node/types/index.js +0 -3
  185. package/lib/node/types/index.js.map +0 -1
  186. package/lib/node/types/misc.d.ts +0 -157
  187. package/lib/node/types/misc.js +0 -3
  188. package/lib/node/types/misc.js.map +0 -1
  189. package/lib/node/types/options.d.ts +0 -191
  190. package/lib/node/types/options.js +0 -3
  191. package/lib/node/types/options.js.map +0 -1
  192. package/lib/node/util.d.ts +0 -21
  193. package/lib/node/util.js +0 -297
  194. package/lib/node/util.js.map +0 -1
  195. package/lib/node/volume.d.ts +0 -395
  196. package/lib/node/volume.js +0 -1641
  197. package/lib/node/volume.js.map +0 -1
  198. package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.d.ts +0 -72
  199. package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.js +0 -217
  200. package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.js.map +0 -1
  201. package/lib/node-to-fsa/NodeFileSystemFileHandle.d.ts +0 -28
  202. package/lib/node-to-fsa/NodeFileSystemFileHandle.js +0 -70
  203. package/lib/node-to-fsa/NodeFileSystemFileHandle.js.map +0 -1
  204. package/lib/node-to-fsa/NodeFileSystemHandle.d.ts +0 -37
  205. package/lib/node-to-fsa/NodeFileSystemHandle.js +0 -68
  206. package/lib/node-to-fsa/NodeFileSystemHandle.js.map +0 -1
  207. package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.d.ts +0 -42
  208. package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.js +0 -97
  209. package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.js.map +0 -1
  210. package/lib/node-to-fsa/NodeFileSystemWritableFileStream.d.ts +0 -56
  211. package/lib/node-to-fsa/NodeFileSystemWritableFileStream.js +0 -191
  212. package/lib/node-to-fsa/NodeFileSystemWritableFileStream.js.map +0 -1
  213. package/lib/node-to-fsa/NodePermissionStatus.d.ts +0 -8
  214. package/lib/node-to-fsa/NodePermissionStatus.js +0 -14
  215. package/lib/node-to-fsa/NodePermissionStatus.js.map +0 -1
  216. package/lib/node-to-fsa/types.d.ts +0 -18
  217. package/lib/node-to-fsa/types.js +0 -3
  218. package/lib/node-to-fsa/types.js.map +0 -1
  219. package/lib/node-to-fsa/util.d.ts +0 -12
  220. package/lib/node-to-fsa/util.js +0 -45
  221. package/lib/node-to-fsa/util.js.map +0 -1
  222. package/lib/node.d.ts +0 -3
  223. package/lib/node.js +0 -10
  224. package/lib/node.js.map +0 -1
  225. package/lib/print/index.d.ts +0 -9
  226. package/lib/print/index.js +0 -49
  227. package/lib/print/index.js.map +0 -1
  228. package/lib/process.d.ts +0 -11
  229. package/lib/process.js +0 -40
  230. package/lib/process.js.map +0 -1
  231. package/lib/queueMicrotask.d.ts +0 -2
  232. package/lib/queueMicrotask.js +0 -6
  233. package/lib/queueMicrotask.js.map +0 -1
  234. package/lib/snapshot/async.d.ts +0 -3
  235. package/lib/snapshot/async.js +0 -59
  236. package/lib/snapshot/async.js.map +0 -1
  237. package/lib/snapshot/binary.d.ts +0 -6
  238. package/lib/snapshot/binary.js +0 -31
  239. package/lib/snapshot/binary.js.map +0 -1
  240. package/lib/snapshot/constants.d.ts +0 -5
  241. package/lib/snapshot/constants.js +0 -3
  242. package/lib/snapshot/constants.js.map +0 -1
  243. package/lib/snapshot/index.d.ts +0 -5
  244. package/lib/snapshot/index.js +0 -8
  245. package/lib/snapshot/index.js.map +0 -1
  246. package/lib/snapshot/json.d.ts +0 -10
  247. package/lib/snapshot/json.js +0 -31
  248. package/lib/snapshot/json.js.map +0 -1
  249. package/lib/snapshot/shared.d.ts +0 -2
  250. package/lib/snapshot/shared.js +0 -6
  251. package/lib/snapshot/shared.js.map +0 -1
  252. package/lib/snapshot/sync.d.ts +0 -3
  253. package/lib/snapshot/sync.js +0 -59
  254. package/lib/snapshot/sync.js.map +0 -1
  255. package/lib/snapshot/types.d.ts +0 -30
  256. package/lib/snapshot/types.js +0 -3
  257. package/lib/snapshot/types.js.map +0 -1
  258. package/lib/vendor/node/buffer.d.ts +0 -1
  259. package/lib/vendor/node/buffer.js +0 -6
  260. package/lib/vendor/node/buffer.js.map +0 -1
  261. package/lib/vendor/node/events.d.ts +0 -1
  262. package/lib/vendor/node/events.js +0 -6
  263. package/lib/vendor/node/events.js.map +0 -1
  264. package/lib/vendor/node/fs.d.ts +0 -6
  265. package/lib/vendor/node/fs.js +0 -4
  266. package/lib/vendor/node/fs.js.map +0 -1
  267. package/lib/vendor/node/internal/buffer.d.ts +0 -9
  268. package/lib/vendor/node/internal/buffer.js +0 -13
  269. package/lib/vendor/node/internal/buffer.js.map +0 -1
  270. package/lib/vendor/node/internal/errors.d.ts +0 -31
  271. package/lib/vendor/node/internal/errors.js +0 -77
  272. package/lib/vendor/node/internal/errors.js.map +0 -1
  273. package/lib/vendor/node/path.d.ts +0 -1
  274. package/lib/vendor/node/path.js +0 -14
  275. package/lib/vendor/node/path.js.map +0 -1
  276. package/lib/vendor/node/stream.d.ts +0 -1
  277. package/lib/vendor/node/stream.js +0 -7
  278. package/lib/vendor/node/stream.js.map +0 -1
  279. package/lib/vendor/node/url.d.ts +0 -1
  280. package/lib/vendor/node/url.js +0 -6
  281. package/lib/vendor/node/url.js.map +0 -1
  282. package/lib/vendor/node/util.d.ts +0 -20
  283. package/lib/vendor/node/util.js +0 -112
  284. package/lib/vendor/node/util.js.map +0 -1
  285. package/src/node-to-fsa/README.md +0 -5
@@ -1,831 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FsaNodeFs = void 0;
4
- const optHelpers = require("../node/options");
5
- const util = require("../node/util");
6
- const buffer_1 = require("../vendor/node/internal/buffer");
7
- const FsPromises_1 = require("../node/FsPromises");
8
- const util_1 = require("./util");
9
- const constants_1 = require("../node/constants");
10
- const encoding_1 = require("../encoding");
11
- const FsaNodeDirent_1 = require("./FsaNodeDirent");
12
- const constants_2 = require("../constants");
13
- const FsaNodeStats_1 = require("./FsaNodeStats");
14
- const queueMicrotask_1 = require("../queueMicrotask");
15
- const FsaNodeWriteStream_1 = require("./FsaNodeWriteStream");
16
- const FsaNodeReadStream_1 = require("./FsaNodeReadStream");
17
- const FsaNodeCore_1 = require("./FsaNodeCore");
18
- const FileHandle_1 = require("../node/FileHandle");
19
- const util_2 = require("../core/util");
20
- const errors = require("../vendor/node/internal/errors");
21
- const notSupported = () => {
22
- throw new Error('Method not supported by the File System Access API.');
23
- };
24
- const notImplemented = () => {
25
- throw new Error('Not implemented');
26
- };
27
- const noop = () => { };
28
- /**
29
- * Constructs a Node.js `fs` API from a File System Access API
30
- * [`FileSystemDirectoryHandle` object](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle).
31
- */
32
- class FsaNodeFs extends FsaNodeCore_1.FsaNodeCore {
33
- constructor() {
34
- // ------------------------------------------------------------ FsPromisesApi
35
- super(...arguments);
36
- this.promises = new FsPromises_1.FsPromises(this, FileHandle_1.FileHandle);
37
- // ------------------------------------------------------------ FsCallbackApi
38
- this.open = (path, flags, a, b) => {
39
- let mode = a;
40
- let callback = b;
41
- if (typeof a === 'function') {
42
- mode = 438 /* MODE.DEFAULT */;
43
- callback = a;
44
- }
45
- mode = mode || 438 /* MODE.DEFAULT */;
46
- const modeNum = util.modeToNumber(mode);
47
- const filename = util.pathToFilename(path);
48
- const flagsNum = util.flagsToNumber(flags);
49
- this.__open(filename, flagsNum, modeNum).then(openFile => callback(null, openFile.fd), error => callback(error));
50
- };
51
- this.close = (fd, callback) => {
52
- (0, util_2.validateFd)(fd);
53
- this.__close(fd).then(() => callback(null), error => callback(error));
54
- };
55
- this.read = (fd, buffer, offset, length, position, callback) => {
56
- util.validateCallback(callback);
57
- // This `if` branch is from Node.js
58
- if (length === 0) {
59
- return (0, queueMicrotask_1.default)(() => {
60
- if (callback)
61
- callback(null, 0, buffer);
62
- });
63
- }
64
- (async () => {
65
- const openFile = await this.getFileByFd(fd, 'read');
66
- const file = await openFile.file.getFile();
67
- const src = await file.arrayBuffer();
68
- position = Number(position);
69
- length = Number(length);
70
- const slice = position > src.byteLength
71
- ? new Uint8Array(0)
72
- : new Uint8Array(src, position, Math.min(length, src.byteLength - position));
73
- const dest = new Uint8Array(buffer.buffer, buffer.byteOffset + offset, slice.length);
74
- dest.set(slice, 0);
75
- return slice.length;
76
- })().then(bytesWritten => callback(null, bytesWritten, buffer), error => callback(error));
77
- };
78
- this.readFile = (id, a, b) => {
79
- const [opts, callback] = optHelpers.optsAndCbGenerator(optHelpers.getReadFileOptions)(a, b);
80
- const flagsNum = util.flagsToNumber(opts.flag);
81
- (async () => {
82
- let fd = typeof id === 'number' ? id : -1;
83
- const originalFd = fd;
84
- try {
85
- if (fd === -1) {
86
- const filename = util.pathToFilename(id);
87
- fd = (await this.__open(filename, flagsNum, 0)).fd;
88
- }
89
- const handle = await this.__getFileById(fd, 'readFile');
90
- const file = await handle.getFile();
91
- const buffer = buffer_1.Buffer.from(await file.arrayBuffer());
92
- return util.bufferToEncoding(buffer, opts.encoding);
93
- }
94
- finally {
95
- try {
96
- const idWasFd = typeof originalFd === 'number' && originalFd >= 0;
97
- if (idWasFd)
98
- await this.__close(originalFd);
99
- }
100
- catch { }
101
- }
102
- })()
103
- .then(data => callback(null, data))
104
- .catch(error => callback(error));
105
- };
106
- this.write = (fd, a, b, c, d, e) => {
107
- const [, asStr, buf, offset, length, position, cb] = util.getWriteArgs(fd, a, b, c, d, e);
108
- (async () => {
109
- const openFile = await this.getFileByFd(fd, 'write');
110
- const data = buf.subarray(offset, offset + length);
111
- await openFile.write(data, position);
112
- return length;
113
- })().then(bytesWritten => cb(null, bytesWritten, asStr ? a : buf), error => cb(error));
114
- };
115
- this.writev = (fd, buffers, a, b) => {
116
- (0, util_2.validateFd)(fd);
117
- let position = null;
118
- let callback;
119
- if (typeof a === 'function') {
120
- callback = a;
121
- }
122
- else {
123
- position = Number(a);
124
- callback = b;
125
- }
126
- util.validateCallback(callback);
127
- (async () => {
128
- const openFile = await this.getFileByFd(fd, 'writev');
129
- const length = buffers.length;
130
- let bytesWritten = 0;
131
- for (let i = 0; i < length; i++) {
132
- const data = buffers[i];
133
- await openFile.write(data, position);
134
- bytesWritten += data.byteLength;
135
- position = null;
136
- }
137
- return bytesWritten;
138
- })().then(bytesWritten => callback(null, bytesWritten, buffers), error => callback(error));
139
- };
140
- this.writeFile = (id, data, a, b) => {
141
- let options = a;
142
- let callback = b;
143
- if (typeof a === 'function') {
144
- options = optHelpers.writeFileDefaults;
145
- callback = a;
146
- }
147
- const cb = util.validateCallback(callback);
148
- const opts = optHelpers.getWriteFileOptions(options);
149
- const flagsNum = util.flagsToNumber(opts.flag);
150
- const modeNum = util.modeToNumber(opts.mode);
151
- const buf = (0, util_2.dataToBuffer)(data, opts.encoding);
152
- (async () => {
153
- let fd = typeof id === 'number' ? id : -1;
154
- const originalFd = fd;
155
- try {
156
- if (fd === -1) {
157
- const filename = util.pathToFilename(id);
158
- fd = (await this.__open(filename, flagsNum, modeNum)).fd;
159
- }
160
- const file = await this.__getFileById(fd, 'writeFile');
161
- const writable = await file.createWritable({ keepExistingData: false });
162
- await writable.write(buf);
163
- await writable.close();
164
- }
165
- finally {
166
- try {
167
- const idWasFd = typeof originalFd === 'number' && originalFd >= 0;
168
- if (idWasFd)
169
- await this.__close(originalFd);
170
- }
171
- catch { }
172
- }
173
- })().then(() => cb(null), error => cb(error));
174
- };
175
- this.copyFile = (src, dest, a, b) => {
176
- const srcFilename = util.pathToFilename(src);
177
- const destFilename = util.pathToFilename(dest);
178
- let flags;
179
- let callback;
180
- if (typeof a === 'function') {
181
- flags = 0;
182
- callback = a;
183
- }
184
- else {
185
- flags = a;
186
- callback = b;
187
- }
188
- util.validateCallback(callback);
189
- const [oldFolder, oldName] = (0, util_1.pathToLocation)(srcFilename);
190
- const [newFolder, newName] = (0, util_1.pathToLocation)(destFilename);
191
- (async () => {
192
- const oldFile = await this.getFile(oldFolder, oldName, 'copyFile');
193
- const newDir = await this.getDir(newFolder, false, 'copyFile');
194
- const newFile = await newDir.getFileHandle(newName, { create: true });
195
- const writable = await newFile.createWritable({ keepExistingData: false });
196
- const oldData = await oldFile.getFile();
197
- await writable.write(await oldData.arrayBuffer());
198
- await writable.close();
199
- })().then(() => callback(null), error => callback(error));
200
- };
201
- /**
202
- * @todo There is a proposal for native "self remove" operation.
203
- * @see https://github.com/whatwg/fs/blob/main/proposals/Remove.md
204
- */
205
- this.unlink = (path, callback) => {
206
- const filename = util.pathToFilename(path);
207
- const [folder, name] = (0, util_1.pathToLocation)(filename);
208
- this.getDir(folder, false, 'unlink')
209
- .then(dir => dir.removeEntry(name))
210
- .then(() => callback(null), error => {
211
- if (error && typeof error === 'object') {
212
- switch (error.name) {
213
- case 'NotFoundError': {
214
- callback(util.createError('ENOENT', 'unlink', filename));
215
- return;
216
- }
217
- case 'InvalidModificationError': {
218
- callback(util.createError('EISDIR', 'unlink', filename));
219
- return;
220
- }
221
- }
222
- }
223
- callback(error);
224
- });
225
- };
226
- this.realpath = (path, a, b) => {
227
- const [opts, callback] = optHelpers.getRealpathOptsAndCb(a, b);
228
- let pathFilename = util.pathToFilename(path);
229
- if (pathFilename[0] !== "/" /* FsaToNodeConstants.Separator */)
230
- pathFilename = "/" /* FsaToNodeConstants.Separator */ + pathFilename;
231
- callback(null, (0, encoding_1.strToEncoding)(pathFilename, opts.encoding));
232
- };
233
- this.stat = (path, a, b) => {
234
- const [{ bigint = false, throwIfNoEntry = true }, callback] = optHelpers.getStatOptsAndCb(a, b);
235
- const filename = util.pathToFilename(path);
236
- const [folder, name] = (0, util_1.pathToLocation)(filename);
237
- (async () => {
238
- const handle = await this.getFileOrDir(folder, name, 'stat');
239
- return await this.getHandleStats(bigint, handle);
240
- })().then(stats => callback(null, stats), error => callback(error));
241
- };
242
- this.lstat = this.stat;
243
- this.fstat = (fd, a, b) => {
244
- const [{ bigint = false, throwIfNoEntry = true }, callback] = optHelpers.getStatOptsAndCb(a, b);
245
- (async () => {
246
- const openFile = await this.getFileByFd(fd, 'fstat');
247
- return await this.getHandleStats(bigint, openFile.file);
248
- })().then(stats => callback(null, stats), error => callback(error));
249
- };
250
- /**
251
- * @todo There is a proposal for native move support.
252
- * @see https://github.com/whatwg/fs/blob/main/proposals/MovingNonOpfsFiles.md
253
- */
254
- this.rename = (oldPath, newPath, callback) => {
255
- const oldPathFilename = util.pathToFilename(oldPath);
256
- const newPathFilename = util.pathToFilename(newPath);
257
- const [oldFolder, oldName] = (0, util_1.pathToLocation)(oldPathFilename);
258
- const [newFolder, newName] = (0, util_1.pathToLocation)(newPathFilename);
259
- (async () => {
260
- const oldFile = await this.getFile(oldFolder, oldName, 'rename');
261
- const newDir = await this.getDir(newFolder, false, 'rename');
262
- const newFile = await newDir.getFileHandle(newName, { create: true });
263
- const writable = await newFile.createWritable({ keepExistingData: false });
264
- const oldData = await oldFile.getFile();
265
- await writable.write(await oldData.arrayBuffer());
266
- await writable.close();
267
- const oldDir = await this.getDir(oldFolder, false, 'rename');
268
- await oldDir.removeEntry(oldName);
269
- })().then(() => callback(null), error => callback(error));
270
- };
271
- this.exists = (path, callback) => {
272
- const filename = util.pathToFilename(path);
273
- if (typeof callback !== 'function')
274
- throw Error(constants_1.ERRSTR.CB);
275
- this.access(path, 0 /* AMODE.F_OK */, error => callback(!error));
276
- };
277
- this.access = (path, a, b) => {
278
- let mode = 0 /* AMODE.F_OK */;
279
- let callback;
280
- if (typeof a !== 'function') {
281
- mode = a | 0; // cast to number
282
- callback = util.validateCallback(b);
283
- }
284
- else {
285
- callback = a;
286
- }
287
- const filename = util.pathToFilename(path);
288
- const [folder, name] = (0, util_1.pathToLocation)(filename);
289
- (async () => {
290
- const node = folder.length || name ? await this.getFileOrDir(folder, name, 'access') : await this.root;
291
- // Check execute permission - not supported by FSA
292
- const checkIfCanExecute = mode & 1 /* AMODE.X_OK */;
293
- if (checkIfCanExecute)
294
- throw util.createError('EACCESS', 'access', filename);
295
- // Use queryPermission to check read/write access
296
- const checkIfCanRead = mode & 4 /* AMODE.R_OK */;
297
- const checkIfCanWrite = mode & 2 /* AMODE.W_OK */;
298
- if (checkIfCanRead || checkIfCanWrite) {
299
- const permissionMode = checkIfCanWrite ? 'readwrite' : 'read';
300
- const permission = await node.queryPermission({ mode: permissionMode });
301
- if (permission.state === 'denied') {
302
- throw util.createError('EACCESS', 'access', filename);
303
- }
304
- }
305
- // If only F_OK is requested, we already verified the file exists by getting the node
306
- })().then(() => callback(null), error => callback(error));
307
- };
308
- this.appendFile = (id, data, a, b) => {
309
- const [opts, callback] = optHelpers.getAppendFileOptsAndCb(a, b);
310
- const buffer = (0, util_2.dataToBuffer)(data, opts.encoding);
311
- this.getFileByIdOrCreate(id, 'appendFile')
312
- .then(file => (async () => {
313
- const blob = await file.getFile();
314
- const writable = await file.createWritable({ keepExistingData: true });
315
- await writable.write({
316
- type: 'write',
317
- data: buffer,
318
- position: blob.size,
319
- });
320
- await writable.close();
321
- })())
322
- .then(() => callback(null), error => callback(error));
323
- };
324
- this.readdir = (path, a, b) => {
325
- const [options, callback] = optHelpers.getReaddirOptsAndCb(a, b);
326
- const filename = util.pathToFilename(path);
327
- const [folder, name] = (0, util_1.pathToLocation)(filename);
328
- if (name)
329
- folder.push(name);
330
- this.getDir(folder, false, 'readdir')
331
- .then(dir => (async () => {
332
- if (options.withFileTypes) {
333
- const list = [];
334
- const parentPath = folder.length ? '/' + folder.join("/" /* FsaToNodeConstants.Separator */) : '/';
335
- for await (const [name, handle] of dir.entries()) {
336
- const dirent = new FsaNodeDirent_1.FsaNodeDirent(name, parentPath, handle.kind);
337
- list.push(dirent);
338
- }
339
- if (!util_2.isWin && options.encoding !== 'buffer')
340
- list.sort((a, b) => {
341
- if (a.name < b.name)
342
- return -1;
343
- if (a.name > b.name)
344
- return 1;
345
- return 0;
346
- });
347
- return list;
348
- }
349
- else {
350
- const list = [];
351
- for await (const key of dir.keys())
352
- list.push(key);
353
- if (!util_2.isWin && options.encoding !== 'buffer')
354
- list.sort();
355
- return list;
356
- }
357
- })())
358
- .then(res => callback(null, res), err => callback(err));
359
- };
360
- this.readlink = (path, a, b) => {
361
- const [opts, callback] = optHelpers.getDefaultOptsAndCb(a, b);
362
- const filename = util.pathToFilename(path);
363
- const buffer = buffer_1.Buffer.from(filename);
364
- callback(null, util.bufferToEncoding(buffer, opts.encoding));
365
- };
366
- /** @todo Could this use `FileSystemSyncAccessHandle.flush` through a Worker thread? */
367
- this.fsync = (fd, callback) => {
368
- callback(null);
369
- };
370
- this.fdatasync = (fd, callback) => {
371
- callback(null);
372
- };
373
- this.ftruncate = (fd, a, b) => {
374
- const len = typeof a === 'number' ? a : 0;
375
- const callback = util.validateCallback(typeof a === 'number' ? b : a);
376
- this.getFileByFdAsync(fd)
377
- .then(file => file.file.createWritable({ keepExistingData: true }))
378
- .then(writable => writable.truncate(len).then(() => writable.close()))
379
- .then(() => callback(null), error => callback(error));
380
- };
381
- this.truncate = (path, a, b) => {
382
- const len = typeof a === 'number' ? a : 0;
383
- const callback = util.validateCallback(typeof a === 'number' ? b : a);
384
- this.open(path, 'r+', (error, fd) => {
385
- if (error)
386
- callback(error);
387
- else {
388
- this.ftruncate(fd, len, error => {
389
- if (error)
390
- this.close(fd, () => callback(error));
391
- else
392
- this.close(fd, callback);
393
- });
394
- }
395
- });
396
- };
397
- this.futimes = (fd, atime, mtime, callback) => {
398
- callback(null);
399
- };
400
- this.utimes = (path, atime, mtime, callback) => {
401
- callback(null);
402
- };
403
- this.mkdir = (path, a, b) => {
404
- const opts = optHelpers.getMkdirOptions(a);
405
- const callback = util.validateCallback(typeof a === 'function' ? a : b);
406
- // const modeNum = modeToNumber(opts.mode, 0o777);
407
- const filename = util.pathToFilename(path);
408
- const [folder, name] = (0, util_1.pathToLocation)(filename);
409
- // TODO: need to throw if directory already exists
410
- this.getDir(folder, opts.recursive ?? false)
411
- .then(dir => dir.getDirectoryHandle(name, { create: true }))
412
- .then(() => callback(null), error => {
413
- if (error && typeof error === 'object') {
414
- switch (error.name) {
415
- case 'NotFoundError': {
416
- const err = util.createError('ENOENT', 'mkdir', folder.join("/" /* FsaToNodeConstants.Separator */));
417
- callback(err);
418
- return;
419
- }
420
- }
421
- }
422
- callback(error);
423
- });
424
- };
425
- this.mkdtemp = (prefix, a, b) => {
426
- const [{ encoding }, callback] = optHelpers.getDefaultOptsAndCb(a, b);
427
- if (!prefix || typeof prefix !== 'string')
428
- throw new TypeError('filename prefix is required');
429
- if (!util.nullCheck(prefix))
430
- return;
431
- const filename = prefix + util.genRndStr6();
432
- this.mkdir(filename, 511 /* MODE.DIR */, err => {
433
- if (err)
434
- callback(err);
435
- else
436
- callback(null, (0, encoding_1.strToEncoding)(filename, encoding));
437
- });
438
- };
439
- this.rmdir = (path, a, b) => {
440
- const options = optHelpers.getRmdirOptions(a);
441
- const callback = util.validateCallback(typeof a === 'function' ? a : b);
442
- const [folder, name] = (0, util_1.pathToLocation)(util.pathToFilename(path));
443
- if (!name && options.recursive)
444
- return this.rmAll(callback);
445
- this.getDir(folder, false, 'rmdir')
446
- .then(dir => dir.getDirectoryHandle(name).then(() => dir))
447
- .then(dir => dir.removeEntry(name, { recursive: options.recursive ?? false }))
448
- .then(() => callback(null), error => {
449
- if (error && typeof error === 'object') {
450
- switch (error.name) {
451
- case 'NotFoundError': {
452
- const err = util.createError('ENOENT', 'rmdir', folder.join("/" /* FsaToNodeConstants.Separator */));
453
- callback(err);
454
- return;
455
- }
456
- case 'InvalidModificationError': {
457
- const err = util.createError('ENOTEMPTY', 'rmdir', folder.join("/" /* FsaToNodeConstants.Separator */));
458
- callback(err);
459
- return;
460
- }
461
- }
462
- }
463
- callback(error);
464
- });
465
- };
466
- this.rm = (path, a, b) => {
467
- const [options, callback] = optHelpers.getRmOptsAndCb(a, b);
468
- const [folder, name] = (0, util_1.pathToLocation)(util.pathToFilename(path));
469
- if (!name && options.recursive)
470
- return this.rmAll(callback);
471
- this.getDir(folder, false, 'rmdir')
472
- .then(dir => dir.removeEntry(name, { recursive: options.recursive ?? false }))
473
- .then(() => callback(null), error => {
474
- if (options.force) {
475
- callback(null);
476
- return;
477
- }
478
- if (error && typeof error === 'object') {
479
- switch (error.name) {
480
- case 'NotFoundError': {
481
- const err = util.createError('ENOENT', 'rmdir', folder.join("/" /* FsaToNodeConstants.Separator */));
482
- callback(err);
483
- return;
484
- }
485
- case 'InvalidModificationError': {
486
- const err = util.createError('ENOTEMPTY', 'rmdir', folder.join("/" /* FsaToNodeConstants.Separator */));
487
- callback(err);
488
- return;
489
- }
490
- }
491
- }
492
- callback(error);
493
- });
494
- };
495
- this.fchmod = (fd, mode, callback) => {
496
- callback(null);
497
- };
498
- this.chmod = (path, mode, callback) => {
499
- callback(null);
500
- };
501
- this.lchmod = (path, mode, callback) => {
502
- callback(null);
503
- };
504
- this.fchown = (fd, uid, gid, callback) => {
505
- callback(null);
506
- };
507
- this.chown = (path, uid, gid, callback) => {
508
- callback(null);
509
- };
510
- this.lchown = (path, uid, gid, callback) => {
511
- callback(null);
512
- };
513
- this.createWriteStream = (path, options) => {
514
- const defaults = {
515
- encoding: 'utf8',
516
- flags: 'w',
517
- autoClose: true,
518
- emitClose: true,
519
- };
520
- const optionsObj = optHelpers.getOptions(defaults, options);
521
- const filename = util.pathToFilename(path);
522
- const flags = util.flagsToNumber(optionsObj.flags ?? 'w');
523
- const fd = optionsObj.fd ? (typeof optionsObj.fd === 'number' ? optionsObj.fd : optionsObj.fd.fd) : 0;
524
- const handle = fd ? this.getFileByFdAsync(fd) : this.__open(filename, flags, 0);
525
- const stream = new FsaNodeWriteStream_1.FsaNodeWriteStream(handle, filename, optionsObj);
526
- if (optionsObj.autoClose) {
527
- stream.once('finish', () => {
528
- handle.then(file => this.close(file.fd, () => { }));
529
- });
530
- stream.once('error', () => {
531
- handle.then(file => this.close(file.fd, () => { }));
532
- });
533
- }
534
- return stream;
535
- };
536
- this.createReadStream = (path, options) => {
537
- const defaults = {
538
- flags: 'r',
539
- fd: null,
540
- mode: 0o666,
541
- autoClose: true,
542
- emitClose: true,
543
- start: 0,
544
- end: Infinity,
545
- highWaterMark: 64 * 1024,
546
- fs: null,
547
- signal: null,
548
- };
549
- const optionsObj = optHelpers.getOptions(defaults, options);
550
- const filename = util.pathToFilename(path);
551
- const flags = util.flagsToNumber(optionsObj.flags);
552
- const fd = optionsObj.fd ? (typeof optionsObj.fd === 'number' ? optionsObj.fd : optionsObj.fd.fd) : 0;
553
- const handle = fd ? this.getFileByFdAsync(fd) : this.__open(filename, flags, 0);
554
- const stream = new FsaNodeReadStream_1.FsaNodeReadStream(this, handle, filename, optionsObj);
555
- return stream;
556
- };
557
- this.openAsBlob = async (path, options) => {
558
- let buffer;
559
- try {
560
- buffer = await new Promise((resolve, reject) => {
561
- this.readFile(path, (err, data) => {
562
- if (err)
563
- reject(err);
564
- else
565
- resolve(data);
566
- });
567
- });
568
- }
569
- catch (error) {
570
- // Convert ENOENT to Node.js-compatible error for openAsBlob
571
- if (error && typeof error === 'object' && error.code === 'ENOENT') {
572
- const nodeError = new errors.TypeError('ERR_INVALID_ARG_VALUE');
573
- throw nodeError;
574
- }
575
- throw error;
576
- }
577
- const type = options?.type || '';
578
- return new Blob([buffer], { type });
579
- };
580
- this.cp = notImplemented;
581
- this.lutimes = notImplemented;
582
- this.opendir = notImplemented;
583
- this.readv = notImplemented;
584
- this.statfs = notImplemented;
585
- this.glob = notImplemented;
586
- /**
587
- * @todo Implement using `FileSystemObserver` class.
588
- * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemObserver
589
- */
590
- this.watchFile = notSupported;
591
- this.unwatchFile = notSupported;
592
- this.watch = notSupported;
593
- this.symlink = notSupported;
594
- this.link = notSupported;
595
- // --------------------------------------------------------- FsSynchronousApi
596
- this.statSync = (path, options) => {
597
- const { bigint = true, throwIfNoEntry = true } = optHelpers.getStatOptions(options);
598
- const filename = util.pathToFilename(path);
599
- const location = (0, util_1.pathToLocation)(filename);
600
- const adapter = this.getSyncAdapter();
601
- const res = adapter.call('stat', location);
602
- const stats = new FsaNodeStats_1.FsaNodeStats(bigint, res.size ?? 0, res.kind);
603
- return stats;
604
- };
605
- this.lstatSync = this.statSync;
606
- this.fstatSync = (fd, options) => {
607
- const filename = this.getFileName(fd);
608
- return this.statSync(filename, options);
609
- };
610
- this.accessSync = (path, mode = 0 /* AMODE.F_OK */) => {
611
- const filename = util.pathToFilename(path);
612
- mode = mode | 0;
613
- const adapter = this.getSyncAdapter();
614
- adapter.call('access', [filename, mode]);
615
- };
616
- this.readFileSync = (id, options) => {
617
- const opts = optHelpers.getReadFileOptions(options);
618
- const flagsNum = util.flagsToNumber(opts.flag);
619
- const filename = this.getFileName(id);
620
- const adapter = this.getSyncAdapter();
621
- const uint8 = adapter.call('readFile', [filename, opts]);
622
- const buffer = buffer_1.Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength);
623
- return util.bufferToEncoding(buffer, opts.encoding);
624
- };
625
- this.writeFileSync = (id, data, options) => {
626
- const opts = optHelpers.getWriteFileOptions(options);
627
- const flagsNum = util.flagsToNumber(opts.flag);
628
- const modeNum = util.modeToNumber(opts.mode);
629
- const buf = (0, util_2.dataToBuffer)(data, opts.encoding);
630
- const filename = this.getFileName(id);
631
- const adapter = this.getSyncAdapter();
632
- adapter.call('writeFile', [filename, util.bufToUint8(buf), opts]);
633
- };
634
- this.appendFileSync = (id, data, options) => {
635
- const opts = optHelpers.getAppendFileOpts(options);
636
- if (!opts.flag || (0, util_2.isFd)(id))
637
- opts.flag = 'a';
638
- const filename = this.getFileName(id);
639
- const buf = (0, util_2.dataToBuffer)(data, opts.encoding);
640
- const adapter = this.getSyncAdapter();
641
- adapter.call('appendFile', [filename, util.bufToUint8(buf), opts]);
642
- };
643
- this.closeSync = (fd) => {
644
- (0, util_2.validateFd)(fd);
645
- const file = this.getFileByFd(fd, 'close');
646
- file.close().catch(() => { });
647
- this.fds.delete(fd);
648
- this.releasedFds.push(fd);
649
- };
650
- this.existsSync = (path) => {
651
- try {
652
- this.statSync(path);
653
- return true;
654
- }
655
- catch {
656
- return false;
657
- }
658
- };
659
- this.copyFileSync = (src, dest, flags) => {
660
- const srcFilename = util.pathToFilename(src);
661
- const destFilename = util.pathToFilename(dest);
662
- const adapter = this.getSyncAdapter();
663
- adapter.call('copy', [srcFilename, destFilename, flags]);
664
- };
665
- this.renameSync = (oldPath, newPath) => {
666
- const srcFilename = util.pathToFilename(oldPath);
667
- const destFilename = util.pathToFilename(newPath);
668
- const adapter = this.getSyncAdapter();
669
- adapter.call('move', [srcFilename, destFilename]);
670
- };
671
- this.rmdirSync = (path, opts) => {
672
- const filename = util.pathToFilename(path);
673
- const adapter = this.getSyncAdapter();
674
- adapter.call('rmdir', [filename, opts]);
675
- };
676
- this.rmSync = (path, options) => {
677
- const filename = util.pathToFilename(path);
678
- const adapter = this.getSyncAdapter();
679
- adapter.call('rm', [filename, options]);
680
- };
681
- this.mkdirSync = (path, options) => {
682
- const opts = optHelpers.getMkdirOptions(options);
683
- const modeNum = util.modeToNumber(opts.mode, 0o777);
684
- const filename = util.pathToFilename(path);
685
- return this.getSyncAdapter().call('mkdir', [filename, options]);
686
- };
687
- this.mkdtempSync = (prefix, options) => {
688
- const { encoding } = optHelpers.getDefaultOpts(options);
689
- if (!prefix || typeof prefix !== 'string')
690
- throw new TypeError('filename prefix is required');
691
- util.nullCheck(prefix);
692
- const result = this.getSyncAdapter().call('mkdtemp', [prefix, options]);
693
- return (0, encoding_1.strToEncoding)(result, encoding);
694
- };
695
- this.readlinkSync = (path, options) => {
696
- const opts = optHelpers.getDefaultOpts(options);
697
- const filename = util.pathToFilename(path);
698
- const buffer = buffer_1.Buffer.from(filename);
699
- return util.bufferToEncoding(buffer, opts.encoding);
700
- };
701
- this.truncateSync = (id, len) => {
702
- if ((0, util_2.isFd)(id))
703
- return this.ftruncateSync(id, len);
704
- const filename = util.pathToFilename(id);
705
- this.getSyncAdapter().call('trunc', [filename, Number(len) || 0]);
706
- };
707
- this.ftruncateSync = (fd, len) => {
708
- const filename = this.getFileName(fd);
709
- this.truncateSync(filename, len);
710
- };
711
- this.unlinkSync = (path) => {
712
- const filename = util.pathToFilename(path);
713
- this.getSyncAdapter().call('unlink', [filename]);
714
- };
715
- this.readdirSync = (path, options) => {
716
- const opts = optHelpers.getReaddirOptions(options);
717
- const filename = util.pathToFilename(path);
718
- const [folder] = (0, util_1.pathToLocation)(filename);
719
- const adapter = this.getSyncAdapter();
720
- const list = adapter.call('readdir', [filename]);
721
- if (opts.withFileTypes) {
722
- const res = [];
723
- const parentPath = folder.length ? '/' + folder.join("/" /* FsaToNodeConstants.Separator */) : '/';
724
- for (const entry of list)
725
- res.push(new FsaNodeDirent_1.FsaNodeDirent(entry.name, parentPath, entry.kind));
726
- return res;
727
- }
728
- else {
729
- const res = [];
730
- for (const entry of list) {
731
- const buffer = buffer_1.Buffer.from(entry.name);
732
- res.push(util.bufferToEncoding(buffer, opts.encoding));
733
- }
734
- return res;
735
- }
736
- };
737
- this.realpathSync = (path, options) => {
738
- let filename = util.pathToFilename(path);
739
- const { encoding } = optHelpers.getRealpathOptions(options);
740
- if (filename[0] !== "/" /* FsaToNodeConstants.Separator */)
741
- filename = "/" /* FsaToNodeConstants.Separator */ + filename;
742
- return (0, encoding_1.strToEncoding)(filename, encoding);
743
- };
744
- this.readSync = (fd, buffer, offset, length, position) => {
745
- (0, util_2.validateFd)(fd);
746
- const filename = this.getFileName(fd);
747
- const adapter = this.getSyncAdapter();
748
- const uint8 = adapter.call('read', [filename, position, length]);
749
- const dest = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
750
- dest.set(uint8, offset);
751
- return uint8.length;
752
- };
753
- this.writeSync = (fd, a, b, c, d) => {
754
- const [, buf, offset, length, position] = util.getWriteSyncArgs(fd, a, b, c, d);
755
- const filename = this.getFileName(fd);
756
- const data = new Uint8Array(buf.buffer, buf.byteOffset + offset, length);
757
- return this.getSyncAdapter().call('write', [filename, data, position || null]);
758
- };
759
- this.openSync = (path, flags, mode = 438 /* MODE.DEFAULT */) => {
760
- const modeNum = util.modeToNumber(mode);
761
- const filename = util.pathToFilename(path);
762
- const flagsNum = util.flagsToNumber(flags);
763
- const adapter = this.getSyncAdapter();
764
- const handle = adapter.call('open', [filename, flagsNum, modeNum]);
765
- const openFile = this.__open2(handle, filename, flagsNum, modeNum);
766
- return openFile.fd;
767
- };
768
- this.writevSync = (fd, buffers, position) => {
769
- if (buffers.length === 0)
770
- return 0;
771
- let bytesWritten = 0;
772
- bytesWritten += this.writeSync(fd, buffers[0], 0, buffers[0].byteLength, position);
773
- for (let i = 1; i < buffers.length; i++) {
774
- bytesWritten += this.writeSync(fd, buffers[i], 0, buffers[i].byteLength, null);
775
- }
776
- return bytesWritten;
777
- };
778
- this.fdatasyncSync = noop;
779
- this.fsyncSync = noop;
780
- this.chmodSync = noop;
781
- this.chownSync = noop;
782
- this.fchmodSync = noop;
783
- this.fchownSync = noop;
784
- this.futimesSync = noop;
785
- this.lchmodSync = noop;
786
- this.lchownSync = noop;
787
- this.utimesSync = noop;
788
- this.lutimesSync = noop;
789
- this.cpSync = notImplemented;
790
- this.opendirSync = notImplemented;
791
- this.statfsSync = notImplemented;
792
- this.readvSync = notImplemented;
793
- this.globSync = notImplemented;
794
- this.symlinkSync = notSupported;
795
- this.linkSync = notSupported;
796
- // ---------------------------------------------------------- FsCommonObjects
797
- this.F_OK = constants_2.constants.F_OK;
798
- this.R_OK = constants_2.constants.R_OK;
799
- this.W_OK = constants_2.constants.W_OK;
800
- this.X_OK = constants_2.constants.X_OK;
801
- this.constants = constants_2.constants;
802
- this.Dirent = FsaNodeDirent_1.FsaNodeDirent;
803
- this.Stats = (FsaNodeStats_1.FsaNodeStats);
804
- this.WriteStream = FsaNodeWriteStream_1.FsaNodeWriteStream;
805
- this.ReadStream = FsaNodeReadStream_1.FsaNodeReadStream;
806
- this.StatFs = 0;
807
- this.Dir = 0;
808
- this.StatsWatcher = 0;
809
- this.FSWatcher = 0;
810
- }
811
- async getHandleStats(bigint, handle) {
812
- let size = 0;
813
- if (handle.kind === 'file') {
814
- const file = handle;
815
- const fileData = await file.getFile();
816
- size = fileData.size;
817
- }
818
- const stats = new FsaNodeStats_1.FsaNodeStats(bigint, bigint ? BigInt(size) : size, handle.kind);
819
- return stats;
820
- }
821
- rmAll(callback) {
822
- (async () => {
823
- const root = await this.root;
824
- for await (const name of root.keys()) {
825
- await root.removeEntry(name, { recursive: true });
826
- }
827
- })().then(() => callback(null), error => callback(error));
828
- }
829
- }
830
- exports.FsaNodeFs = FsaNodeFs;
831
- //# sourceMappingURL=FsaNodeFs.js.map