@fncts/node 0.0.43 → 0.0.45

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 (43) hide show
  1. package/LICENSE +26 -0
  2. package/_cjs/chunk.cjs +28 -0
  3. package/_cjs/fs/api.cjs +289 -276
  4. package/_cjs/fs/api.cjs.map +1 -1
  5. package/_cjs/fs.cjs +46 -17
  6. package/_cjs/global.cjs +0 -2
  7. package/_cjs/http/IncomingMessage.cjs +60 -55
  8. package/_cjs/http/IncomingMessage.cjs.map +1 -1
  9. package/_cjs/http/Server.cjs +180 -195
  10. package/_cjs/http/Server.cjs.map +1 -1
  11. package/_cjs/http/ServerRequest.cjs +41 -39
  12. package/_cjs/http/ServerRequest.cjs.map +1 -1
  13. package/_cjs/index.cjs +0 -2
  14. package/_cjs/stream/api.cjs +215 -220
  15. package/_cjs/stream/api.cjs.map +1 -1
  16. package/_cjs/stream.cjs +10 -17
  17. package/_mjs/fs/api.mjs +296 -300
  18. package/_mjs/fs/api.mjs.map +1 -1
  19. package/_mjs/fs.mjs +2 -3
  20. package/_mjs/global.mjs +0 -2
  21. package/_mjs/http/IncomingMessage.mjs +49 -45
  22. package/_mjs/http/IncomingMessage.mjs.map +1 -1
  23. package/_mjs/http/Server.mjs +139 -169
  24. package/_mjs/http/Server.mjs.map +1 -1
  25. package/_mjs/http/ServerRequest.mjs +36 -29
  26. package/_mjs/http/ServerRequest.mjs.map +1 -1
  27. package/_mjs/index.mjs +0 -2
  28. package/_mjs/stream/api.mjs +164 -187
  29. package/_mjs/stream/api.mjs.map +1 -1
  30. package/_mjs/stream.mjs +2 -3
  31. package/_src/fs/api.ts +8 -9
  32. package/_src/stream/api.ts +16 -0
  33. package/fs/api.d.ts +1 -1
  34. package/http/Server.d.ts +1 -1
  35. package/package.json +7 -3
  36. package/_cjs/fs.cjs.map +0 -1
  37. package/_cjs/global.cjs.map +0 -1
  38. package/_cjs/index.cjs.map +0 -1
  39. package/_cjs/stream.cjs.map +0 -1
  40. package/_mjs/fs.mjs.map +0 -1
  41. package/_mjs/global.mjs.map +0 -1
  42. package/_mjs/index.mjs.map +0 -1
  43. package/_mjs/stream.mjs.map +0 -1
package/_mjs/fs/api.mjs CHANGED
@@ -1,311 +1,307 @@
1
- const fileName_1 = "(@fncts/node) src/fs/api.ts";
2
- import * as tsplus_module_1 from "@fncts/base/data/Newtype";
1
+ import * as tsplus_module_21 from "@fncts/io/Queue/constructors";
3
2
  import * as tsplus_module_2 from "@fncts/io/IO/api";
3
+ import * as tsplus_module_19 from "@fncts/io/Queue/api/operations";
4
+ import * as tsplus_module_11 from "@fncts/io/Channel/api";
5
+ import * as tsplus_module_10 from "@fncts/base/data/Maybe/definition";
6
+ import * as tsplus_module_16 from "@fncts/base/data/Either/constructors";
7
+ import * as tsplus_module_20 from "@fncts/io/IO/runtime";
8
+ import * as tsplus_module_12 from "@fncts/io/Channel/core-api";
9
+ import * as tsplus_module_18 from "@fncts/base/collection/immutable/Conc/api";
10
+ import * as tsplus_module_9 from "@fncts/io/Sink/definition";
11
+ import * as tsplus_module_15 from "@fncts/io/IO/api/acquireRelease";
12
+ import * as tsplus_module_7 from "@fncts/io/Stream/api";
4
13
  import * as tsplus_module_3 from "@fncts/base/collection/immutable/Conc/constructors";
5
- import * as tsplus_module_4 from "@fncts/io/Ref/api/set";
6
14
  import * as tsplus_module_5 from "@fncts/base/data/Maybe/constructors";
15
+ import * as tsplus_module_1 from "@fncts/base/data/Newtype";
16
+ import * as tsplus_module_4 from "@fncts/io/Ref/api/set";
7
17
  import * as tsplus_module_6 from "@fncts/io/Ref/api/get";
8
- import * as tsplus_module_7 from "@fncts/io/Stream/api";
9
18
  import * as tsplus_module_8 from "@fncts/io/Ref/constructors";
10
- import * as tsplus_module_9 from "@fncts/io/Sink/definition";
11
- import * as tsplus_module_10 from "@fncts/base/data/Maybe/definition";
12
- import * as tsplus_module_11 from "@fncts/io/Channel/api";
13
- import * as tsplus_module_12 from "@fncts/io/Channel/core-api";
14
19
  import * as tsplus_module_13 from "@fncts/base/data/Cause/api";
15
20
  import * as tsplus_module_14 from "@fncts/io/Ref/api/modify";
16
- import * as tsplus_module_15 from "@fncts/io/IO/api/acquireRelease";
17
- import * as tsplus_module_16 from "@fncts/base/data/Either/constructors";
18
21
  import * as tsplus_module_17 from "@fncts/io/IO/api/asyncInterrupt";
19
- import * as tsplus_module_18 from "@fncts/base/collection/immutable/Conc/api";
20
- import * as tsplus_module_19 from "@fncts/io/Queue/api/operations";
21
- import * as tsplus_module_20 from "@fncts/io/IO/runtime";
22
- import * as tsplus_module_21 from "@fncts/io/Queue/constructors";
23
22
  import * as fs from "fs";
24
- export const FileDescriptor = /*#__PURE__*/tsplus_module_1.newtype();
23
+ //#region build/esm/fs/api.js
24
+ const fileName_1 = "(@fncts/node) src/fs/api.ts";
25
+ const FileDescriptor = tsplus_module_1.newtype();
25
26
  function unitErrorCallback(cb) {
26
- return err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":18:36")) : cb(tsplus_module_2.unit);
27
- }
28
- export function access(path, mode) {
29
- return tsplus_module_2.async(cb => {
30
- fs.access(path, mode, err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":23:53")) : cb(tsplus_module_2.unit));
31
- });
32
- }
33
- export function appendFile(path, data, options) {
34
- return tsplus_module_2.async(cb => {
35
- fs.appendFile(path, data, options ?? {}, err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":33:79")) : cb(tsplus_module_2.unit));
36
- });
37
- }
38
- export function chmod(path, mode) {
39
- return tsplus_module_2.async(cb => {
40
- fs.chmod(path, mode, err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":39:52")) : cb(tsplus_module_2.unit));
41
- });
42
- }
43
- export function close(fd) {
44
- return tsplus_module_2.async(cb => {
45
- fs.close(FileDescriptor.reverseGet(fd), err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":45:71")) : cb(tsplus_module_2.unit));
46
- });
47
- }
48
- export function chown(path, uid, gid) {
49
- return tsplus_module_2.async(cb => {
50
- fs.chown(path, uid, gid, err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":51:56")) : cb(tsplus_module_2.unit));
51
- });
52
- }
53
- export function copyFile(src, dest, flags) {
54
- return tsplus_module_2.async(cb => {
55
- fs.copyFile(src, dest, flags, err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":57:61")) : cb(tsplus_module_2.unit));
56
- });
57
- }
58
- export function createReadStream(path, options) {
59
- const chunkSize = options?.chunkSize ?? 1024 * 64;
60
- return tsplus_module_7.flatMap(([fd, state]) => tsplus_module_7.repeatIOChunkMaybe(tsplus_module_2.flatMap(([pos, end]) => {
61
- const n = Math.min(end - pos + 1, chunkSize);
62
- return tsplus_module_2.flatMap(([bytes, chunk]) => tsplus_module_2.flatMap(() => tsplus_module_2.map(() => {
63
- if (bytes !== chunk.length) {
64
- const dst = Buffer.allocUnsafeSlow(bytes);
65
- chunk.copy(dst, 0, 0, bytes);
66
- return tsplus_module_3.fromBuffer(dst);
67
- } else {
68
- return tsplus_module_3.fromBuffer(chunk);
69
- }
70
- }, fileName_1 + ":95:10")(tsplus_module_4.set([pos + n, end], fileName_1 + ":95:20")(state)), fileName_1 + ":94:10")(tsplus_module_2.when(() => bytes === 0, fileName_1 + ":94:34")(tsplus_module_2.fail(() => tsplus_module_5.nothing(fileName_1 + ":94:26"), fileName_1 + ":94:18"))), fileName_1 + ":92:33")(tsplus_module_2.mapError(tsplus_module_5.just, fileName_1 + ":92:59")(read(fd, n, pos)));
71
- }, fileName_1 + ":90:33")(tsplus_module_6.get(state, fileName_1 + ":90:39")), fileName_1 + ":88:30"), fileName_1 + ":87:12")(tsplus_module_7.acquireRelease(tsplus_module_2.zip(tsplus_module_2.defer(() => {
72
- const start = options?.start ?? 0;
73
- const end = options?.end ?? Infinity;
74
- if (end < start) {
75
- return tsplus_module_2.fail(() => new RangeError(`start (${start}) must be <= end (${end})`), fileName_1 + ":80:25");
76
- } else {
77
- return tsplus_module_8.make(() => [start, end], fileName_1 + ":82:26");
78
- }
79
- }, fileName_1 + ":76:15"), fileName_1 + ":75:75")(open(path, options?.flags ?? fs.constants.O_RDONLY, options?.mode)), ([fd, _]) => tsplus_module_2.orHalt(close(fd), fileName_1 + ":86:27"), fileName_1 + ":74:31"));
80
- }
81
- export function createWriteSink(path, options) {
82
- return new tsplus_module_9.Sink(tsplus_module_11.unwrapScoped(() => tsplus_module_2.flatMap(errorRef => tsplus_module_2.flatMap(st => tsplus_module_2.map(maybeError => {
83
- if (!st && tsplus_module_10.isJust(maybeError)) {
84
- const reader = tsplus_module_11.readWith(_ => tsplus_module_12.zipRight(tsplus_module_12.end(() => undefined))(tsplus_module_11.fail(() => maybeError.value)), err => tsplus_module_12.failCause(() => tsplus_module_13.sequential(tsplus_module_13.fail(maybeError.value), tsplus_module_13.fail(err))), _ => tsplus_module_11.fail(() => maybeError.value));
85
- return reader;
86
- } else {
87
- const reader = tsplus_module_11.readWith(inp => tsplus_module_11.unwrap(() => tsplus_module_2.map(() => reader, fileName_1 + ":152:23")(tsplus_module_2.flatMap(() => tsplus_module_14.update(n => n !== undefined ? n + inp.length : undefined, fileName_1 + ":151:47")(st[1]), fileName_1 + ":151:27")(tsplus_module_2.flatMap(pos => write(st[0], inp, pos), fileName_1 + ":150:27")(tsplus_module_6.get(st[1], fileName_1 + ":149:23"))))), err => tsplus_module_11.fail(() => err), _ => tsplus_module_12.end(() => undefined));
88
- return reader;
89
- }
90
- }, fileName_1 + ":129:29")(tsplus_module_6.get(errorRef, fileName_1 + ":129:38")), fileName_1 + ":122:27")(tsplus_module_2.catchAll(err => tsplus_module_4.set(tsplus_module_5.just(err, fileName_1 + ":126:49"), fileName_1 + ":126:44")(errorRef), fileName_1 + ":126:22")(tsplus_module_15.acquireRelease(() => tsplus_module_2.zip(tsplus_module_8.make(() => options?.start ?? undefined, fileName_1 + ":124:26"), fileName_1 + ":124:17")(open(path, options?.flags ?? fs.constants.O_CREAT | fs.constants.O_WRONLY, options?.mode)), ([fd, _]) => tsplus_module_2.orHalt(close(fd), fileName_1 + ":125:51"), fileName_1 + ":125:28"))), fileName_1 + ":121:27")(tsplus_module_8.make(() => tsplus_module_5.nothing(fileName_1 + ":121:67"), fileName_1 + ":121:36"))));
91
- }
92
- export function fchmod(fd, mode) {
93
- return tsplus_module_2.async(cb => {
94
- fs.fchmod(FileDescriptor.reverseGet(fd), mode, unitErrorCallback(cb));
95
- });
96
- }
97
- export function fchown(fd, uid, gid) {
98
- return tsplus_module_2.async(cb => {
99
- fs.fchown(FileDescriptor.reverseGet(fd), uid, gid, unitErrorCallback(cb));
100
- });
101
- }
102
- export function fdatasync(fd) {
103
- return tsplus_module_2.async(cb => {
104
- fs.fdatasync(FileDescriptor.reverseGet(fd), unitErrorCallback(cb));
105
- });
106
- }
107
- export function fstat(fd) {
108
- return tsplus_module_2.async(cb => {
109
- fs.fstat(FileDescriptor.reverseGet(fd), (err, stats) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":184:78")) : cb(tsplus_module_2.succeedNow(stats, fileName_1 + ":184:103")));
110
- });
111
- }
112
- export function fsync(fd) {
113
- return tsplus_module_2.async(cb => {
114
- fs.fsync(FileDescriptor.reverseGet(fd), unitErrorCallback(cb));
115
- });
116
- }
117
- export function ftruncate(fd, len) {
118
- return tsplus_module_2.async(cb => {
119
- fs.ftruncate(FileDescriptor.reverseGet(fd), len, unitErrorCallback(cb));
120
- });
121
- }
122
- export function futimes(fd, atime, mtime) {
123
- return tsplus_module_2.async(cb => {
124
- fs.futimes(FileDescriptor.reverseGet(fd), atime, mtime, unitErrorCallback(cb));
125
- });
126
- }
127
- export function lchmod(path, mode) {
128
- return tsplus_module_2.async(cb => {
129
- fs.lchmod(path, mode, unitErrorCallback(cb));
130
- });
131
- }
132
- export function lchown(path, uid, gid) {
133
- return tsplus_module_2.async(cb => {
134
- fs.lchown(path, uid, gid, unitErrorCallback(cb));
135
- });
136
- }
137
- export function lutimes(path, atime, mtime) {
138
- return tsplus_module_2.async(cb => {
139
- fs.lutimes(path, atime, mtime, unitErrorCallback(cb));
140
- });
141
- }
142
- export function link(path, newPath) {
143
- return tsplus_module_2.async(cb => {
144
- fs.link(path, newPath, err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":234:54")) : cb(tsplus_module_2.unit));
145
- });
146
- }
147
- export function lstat(path) {
148
- return tsplus_module_2.async(cb => {
149
- fs.lstat(path, (err, stats) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":240:53")) : cb(tsplus_module_2.succeedNow(stats, fileName_1 + ":240:78")));
150
- });
151
- }
152
- export function mkdir(path, options) {
153
- return tsplus_module_2.async(cb => {
154
- fs.mkdir(path, options, (err, path) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":249:61")) : cb(tsplus_module_2.succeed(() => tsplus_module_5.fromNullable(path), fileName_1 + ":249:83")));
155
- });
156
- }
157
- export function mkdtemp(prefix, options) {
158
- return tsplus_module_2.async(cb => {
159
- fs.mkdtemp(prefix, options, (err, folder) => err ? cb(tsplus_module_2.failNow(err, fileName_1 + ":255:70")) : cb(tsplus_module_2.succeedNow(folder, fileName_1 + ":255:95")));
160
- });
161
- }
162
- export function open(path, flags, mode) {
163
- return tsplus_module_2.async(cb => {
164
- fs.open(path, flags, mode ?? null, (err, fd) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":265:70")) : cb(tsplus_module_2.succeed(() => FileDescriptor.get(fd), fileName_1 + ":265:92")));
165
- });
166
- }
167
- export class Dir {
168
- constructor(dir) {
169
- this.path = dir.path;
170
- this._dir = dir;
171
- }
172
- close() {
173
- return tsplus_module_2.async(cb => {
174
- this._dir.close(unitErrorCallback(cb));
175
- });
176
- }
177
- read() {
178
- return tsplus_module_2.async(cb => {
179
- this._dir.read((err, dirEnt) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":285:56")) : cb(tsplus_module_2.succeedNow(tsplus_module_5.fromNullable(dirEnt), fileName_1 + ":285:81")));
180
- });
181
- }
182
- }
183
- export function opendir(path, options) {
184
- return tsplus_module_2.async(cb => {
185
- fs.opendir(path, options ?? {}, (err, dir) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":292:75")) : cb(tsplus_module_2.succeedNow(new Dir(dir), fileName_1 + ":292:100")));
186
- });
187
- }
188
- export function read(fd, length, position) {
189
- return tsplus_module_2.async(cb => {
190
- const buf = Buffer.alloc(length);
191
- fs.read(FileDescriptor.reverseGet(fd), buf, 0, length, position ?? null, (err, bytesRead, buffer) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":304:23")) : cb(tsplus_module_2.succeed(() => [bytesRead, buffer], fileName_1 + ":304:45")));
192
- });
193
- }
194
- export function readFile(file, options = {}) {
195
- return tsplus_module_17.asyncInterrupt(cb => {
196
- const abortController = new AbortController();
197
- fs.readFile(file, {
198
- ...options,
199
- signal: abortController.signal
200
- }, (err, data) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":321:23")) : cb(tsplus_module_2.succeedNow(data, fileName_1 + ":321:48")));
201
- return tsplus_module_16.left(tsplus_module_2.succeed(() => abortController.abort(), fileName_1 + ":323:34"), fileName_1 + ":323:23");
202
- });
203
- }
204
- export function readdir(path, options) {
205
- return tsplus_module_2.async(cb => {
206
- fs.readdir(path, options ?? {}, (err, files) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":357:23")) : files[0] && files[0] instanceof fs.Dir ? files.map(a => new Dir(a)) : files);
207
- });
208
- }
209
- export function realpath(path, options) {
210
- return tsplus_module_2.async(cb => {
211
- fs.realpath(path, options ?? {}, (err, resolvedPath) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":376:78")) : cb(tsplus_module_2.succeedNow(resolvedPath, fileName_1 + ":376:103")));
212
- });
213
- }
214
- export function realpathNative(path, options) {
215
- return tsplus_module_2.async(cb => {
216
- fs.realpath.native(path, options ?? {}, (err, resolvedPath) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":395:23")) : cb(tsplus_module_2.succeed(() => resolvedPath, fileName_1 + ":395:45")));
217
- });
218
- }
219
- export function rename(oldPath, newPath) {
220
- return tsplus_module_2.async(cb => {
221
- fs.rename(oldPath, newPath, unitErrorCallback(cb));
222
- });
223
- }
224
- export function rm(path, options) {
225
- return tsplus_module_2.async(cb => {
226
- fs.rm(path, options ?? {}, unitErrorCallback(cb));
227
- });
228
- }
229
- export function rmdir(path, options) {
230
- return tsplus_module_2.async(cb => {
231
- fs.rmdir(path, options ?? {}, unitErrorCallback(cb));
232
- });
233
- }
234
- export function stat(path, options) {
235
- return tsplus_module_2.async(cb => {
236
- fs.stat(path, options ?? {}, (err, stats) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":425:76")) : cb(tsplus_module_2.succeedNow(stats, fileName_1 + ":425:101")));
237
- });
238
- }
239
- export function symlink(target, path) {
240
- return tsplus_module_2.async(cb => {
241
- fs.symlink(target, path, unitErrorCallback(cb));
242
- });
243
- }
244
- export function truncate(path, len) {
245
- return tsplus_module_2.async(cb => {
246
- fs.truncate(path, len, unitErrorCallback(cb));
247
- });
248
- }
249
- export function unlink(path) {
250
- return tsplus_module_2.async(cb => {
251
- fs.unlink(path, unitErrorCallback(cb));
252
- });
253
- }
254
- export function utimes(path, atime, mtime) {
255
- return tsplus_module_2.async(cb => {
256
- fs.utimes(path, atime, mtime, unitErrorCallback(cb));
257
- });
258
- }
259
- export function write(fd, buffer, position) {
260
- return tsplus_module_2.async(cb => {
261
- const b = tsplus_module_18.toBuffer(buffer);
262
- fs.write(FileDescriptor.reverseGet(fd), b, position ?? null, b.byteLength, (err, bytesWritten) => err ? cb(tsplus_module_2.failNow(err, fileName_1 + ":461:26")) : cb(tsplus_module_2.succeedNow(bytesWritten, fileName_1 + ":461:51")));
263
- });
264
- }
265
- export function writeFile(file, data, options = {}) {
266
- return tsplus_module_17.asyncInterrupt(cb => {
267
- const abortController = new AbortController();
268
- fs.writeFile(file, data, {
269
- ...options,
270
- signal: abortController.signal
271
- }, err => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":480:23")) : tsplus_module_2.unit);
272
- return tsplus_module_16.left(tsplus_module_2.succeed(() => abortController.abort(), fileName_1 + ":482:34"), fileName_1 + ":482:23");
273
- });
274
- }
275
- export function writev(fd, buffers, position) {
276
- return tsplus_module_2.async(cb => {
277
- if (position) {
278
- fs.writev(FileDescriptor.reverseGet(fd), buffers, position, (err, bytesWritten) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":494:25")) : cb(tsplus_module_2.succeedNow(bytesWritten, fileName_1 + ":494:50")));
279
- } else {
280
- fs.writev(FileDescriptor.reverseGet(fd), buffers, (err, bytesWritten) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":498:25")) : cb(tsplus_module_2.succeedNow(bytesWritten, fileName_1 + ":498:50")));
281
- }
282
- });
283
- }
284
- export function watch(filename, options) {
285
- return tsplus_module_7.flatMap(watcher => tsplus_module_7.repeatIOMaybe(tsplus_module_2.async(cb => {
286
- watcher.once("change", (eventType, filename) => {
287
- watcher.removeAllListeners();
288
- cb(tsplus_module_2.succeedNow({
289
- eventType: eventType,
290
- filename
291
- }, fileName_1 + ":534:27"));
292
- });
293
- watcher.once("error", error => {
294
- watcher.removeAllListeners();
295
- cb(tsplus_module_2.failNow(tsplus_module_5.just(error, fileName_1 + ":538:29"), fileName_1 + ":538:24"));
296
- });
297
- watcher.once("close", () => {
298
- watcher.removeAllListeners();
299
- cb(tsplus_module_2.failNow(tsplus_module_5.nothing(fileName_1 + ":542:32"), fileName_1 + ":542:24"));
300
- });
301
- }), fileName_1 + ":530:25"), fileName_1 + ":529:12")(tsplus_module_7.fromIO(tsplus_module_2.tryCatch(() => fs.watch(filename, options ?? {}), err => err, fileName_1 + ":525:16"), fileName_1 + ":524:23"));
302
- }
303
- export function watchFile(filename, options) {
304
- return tsplus_module_7.flatMap(queue => tsplus_module_7.repeatIOMaybe(tsplus_module_19.take(queue, fileName_1 + ":579:50"), fileName_1 + ":579:44"), fileName_1 + ":579:12")(tsplus_module_7.acquireRelease(tsplus_module_2.flatMap(queue => tsplus_module_2.map(runtime => {
305
- fs.watchFile(filename, options ?? {}, (curr, prev) => {
306
- runtime.unsafeRunFiber(tsplus_module_19.offer([curr, prev], fileName_1 + ":574:43")(queue), fileName_1 + ":574:31");
307
- });
308
- return queue;
309
- }, fileName_1 + ":572:24")(tsplus_module_20.runtime(fileName_1 + ":572:35")), fileName_1 + ":571:24")(tsplus_module_21.makeUnbounded(fileName_1 + ":571:44")), queue => tsplus_module_19.shutdown(queue, fileName_1 + ":578:21"), fileName_1 + ":569:31"));
310
- }
27
+ return (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":17:36")) : cb(tsplus_module_2.unit);
28
+ }
29
+ function access(path, mode) {
30
+ return tsplus_module_2.async((cb) => {
31
+ fs.access(path, mode, (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":22:53")) : cb(tsplus_module_2.unit));
32
+ });
33
+ }
34
+ function appendFile(path, data, options) {
35
+ return tsplus_module_2.async((cb) => {
36
+ fs.appendFile(path, data, options ?? {}, (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":32:79")) : cb(tsplus_module_2.unit));
37
+ });
38
+ }
39
+ function chmod(path, mode) {
40
+ return tsplus_module_2.async((cb) => {
41
+ fs.chmod(path, mode, (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":38:52")) : cb(tsplus_module_2.unit));
42
+ });
43
+ }
44
+ function close(fd) {
45
+ return tsplus_module_2.async((cb) => {
46
+ fs.close(FileDescriptor.reverseGet(fd), (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":44:71")) : cb(tsplus_module_2.unit));
47
+ });
48
+ }
49
+ function chown(path, uid, gid) {
50
+ return tsplus_module_2.async((cb) => {
51
+ fs.chown(path, uid, gid, (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":50:56")) : cb(tsplus_module_2.unit));
52
+ });
53
+ }
54
+ function copyFile(src, dest, flags) {
55
+ return tsplus_module_2.async((cb) => {
56
+ fs.copyFile(src, dest, flags, (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":56:61")) : cb(tsplus_module_2.unit));
57
+ });
58
+ }
59
+ function createReadStream(path, options) {
60
+ const chunkSize = options?.chunkSize ?? 1024 * 64;
61
+ return tsplus_module_7.flatMap(([fd, state]) => tsplus_module_7.repeatIOChunkMaybe(tsplus_module_2.flatMap(([pos, end]) => {
62
+ const n = Math.min(end - pos + 1, chunkSize);
63
+ return tsplus_module_2.flatMap(([bytes, chunk]) => tsplus_module_2.flatMap(() => tsplus_module_2.map(() => {
64
+ if (bytes !== chunk.length) {
65
+ const dst = Buffer.allocUnsafeSlow(bytes);
66
+ chunk.copy(dst, 0, 0, bytes);
67
+ return tsplus_module_3.fromBuffer(dst);
68
+ } else return tsplus_module_3.fromBuffer(chunk);
69
+ }, fileName_1 + ":94:10")(tsplus_module_4.set([pos + n, end], fileName_1 + ":94:20")(state)), fileName_1 + ":93:10")(tsplus_module_2.when(() => bytes === 0, fileName_1 + ":93:34")(tsplus_module_2.fail(() => tsplus_module_5.nothing(fileName_1 + ":93:26"), fileName_1 + ":93:18"))), fileName_1 + ":91:33")(tsplus_module_2.mapError(tsplus_module_5.just, fileName_1 + ":91:59")(read(fd, n, pos)));
70
+ }, fileName_1 + ":89:33")(tsplus_module_6.get(state, fileName_1 + ":89:39")), fileName_1 + ":87:30"), fileName_1 + ":86:12")(tsplus_module_7.acquireRelease(tsplus_module_2.zip(tsplus_module_2.defer(() => {
71
+ const start = options?.start ?? 0;
72
+ const end = options?.end ?? Infinity;
73
+ if (end < start) return tsplus_module_2.fail(() => /* @__PURE__ */ new RangeError(`start (${start}) must be <= end (${end})`), fileName_1 + ":79:25");
74
+ else return tsplus_module_8.make(() => [start, end], fileName_1 + ":81:26");
75
+ }, fileName_1 + ":75:15"), fileName_1 + ":74:75")(open(path, options?.flags ?? fs.constants.O_RDONLY, options?.mode)), ([fd, _]) => tsplus_module_2.orHalt(close(fd), fileName_1 + ":85:27"), fileName_1 + ":73:31"));
76
+ }
77
+ function createWriteSink(path, options) {
78
+ return new tsplus_module_9.Sink(tsplus_module_11.unwrapScoped(() => tsplus_module_2.flatMap((errorRef) => tsplus_module_2.flatMap((st) => tsplus_module_2.map((maybeError) => {
79
+ if (!st && tsplus_module_10.isJust(maybeError)) return tsplus_module_11.readWith((_) => tsplus_module_12.zipRight(tsplus_module_12.end(() => void 0))(tsplus_module_11.fail(() => maybeError.value)), (err) => tsplus_module_12.failCause(() => tsplus_module_13.sequential(tsplus_module_13.fail(maybeError.value), tsplus_module_13.fail(err))), (_) => tsplus_module_11.fail(() => maybeError.value));
80
+ else {
81
+ const reader = tsplus_module_11.readWith((inp) => tsplus_module_11.unwrap(() => tsplus_module_2.map(() => reader, fileName_1 + ":151:23")(tsplus_module_2.flatMap(() => tsplus_module_14.update((n) => n !== void 0 ? n + inp.length : void 0, fileName_1 + ":150:47")(st[1]), fileName_1 + ":150:27")(tsplus_module_2.flatMap((pos) => write(st[0], inp, pos), fileName_1 + ":149:27")(tsplus_module_6.get(st[1], fileName_1 + ":148:23"))))), (err) => tsplus_module_11.fail(() => err), (_) => tsplus_module_12.end(() => void 0));
82
+ return reader;
83
+ }
84
+ }, fileName_1 + ":128:29")(tsplus_module_6.get(errorRef, fileName_1 + ":128:38")), fileName_1 + ":121:27")(tsplus_module_2.catchAll((err) => tsplus_module_4.set(tsplus_module_5.just(err, fileName_1 + ":125:49"), fileName_1 + ":125:44")(errorRef), fileName_1 + ":125:22")(tsplus_module_15.acquireRelease(() => tsplus_module_2.zip(tsplus_module_8.make(() => options?.start ?? void 0, fileName_1 + ":123:26"), fileName_1 + ":123:17")(open(path, options?.flags ?? fs.constants.O_CREAT | fs.constants.O_WRONLY, options?.mode)), ([fd, _]) => tsplus_module_2.orHalt(close(fd), fileName_1 + ":124:51"), fileName_1 + ":124:28"))), fileName_1 + ":120:27")(tsplus_module_8.make(() => tsplus_module_5.nothing(fileName_1 + ":120:67"), fileName_1 + ":120:36"))));
85
+ }
86
+ function fchmod(fd, mode) {
87
+ return tsplus_module_2.async((cb) => {
88
+ fs.fchmod(FileDescriptor.reverseGet(fd), mode, unitErrorCallback(cb));
89
+ });
90
+ }
91
+ function fchown(fd, uid, gid) {
92
+ return tsplus_module_2.async((cb) => {
93
+ fs.fchown(FileDescriptor.reverseGet(fd), uid, gid, unitErrorCallback(cb));
94
+ });
95
+ }
96
+ function fdatasync(fd) {
97
+ return tsplus_module_2.async((cb) => {
98
+ fs.fdatasync(FileDescriptor.reverseGet(fd), unitErrorCallback(cb));
99
+ });
100
+ }
101
+ function fstat(fd) {
102
+ return tsplus_module_2.async((cb) => {
103
+ fs.fstat(FileDescriptor.reverseGet(fd), (err, stats) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":183:78")) : cb(tsplus_module_2.succeedNow(stats, fileName_1 + ":183:103")));
104
+ });
105
+ }
106
+ function fsync(fd) {
107
+ return tsplus_module_2.async((cb) => {
108
+ fs.fsync(FileDescriptor.reverseGet(fd), unitErrorCallback(cb));
109
+ });
110
+ }
111
+ function ftruncate(fd, len) {
112
+ return tsplus_module_2.async((cb) => {
113
+ fs.ftruncate(FileDescriptor.reverseGet(fd), len, unitErrorCallback(cb));
114
+ });
115
+ }
116
+ function futimes(fd, atime, mtime) {
117
+ return tsplus_module_2.async((cb) => {
118
+ fs.futimes(FileDescriptor.reverseGet(fd), atime, mtime, unitErrorCallback(cb));
119
+ });
120
+ }
121
+ function lchmod(path, mode) {
122
+ return tsplus_module_2.async((cb) => {
123
+ fs.lchmod(path, mode, unitErrorCallback(cb));
124
+ });
125
+ }
126
+ function lchown(path, uid, gid) {
127
+ return tsplus_module_2.async((cb) => {
128
+ fs.lchown(path, uid, gid, unitErrorCallback(cb));
129
+ });
130
+ }
131
+ function lutimes(path, atime, mtime) {
132
+ return tsplus_module_2.async((cb) => {
133
+ fs.lutimes(path, atime, mtime, unitErrorCallback(cb));
134
+ });
135
+ }
136
+ function link(path, newPath) {
137
+ return tsplus_module_2.async((cb) => {
138
+ fs.link(path, newPath, (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":233:54")) : cb(tsplus_module_2.unit));
139
+ });
140
+ }
141
+ function lstat(path) {
142
+ return tsplus_module_2.async((cb) => {
143
+ fs.lstat(path, (err, stats) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":239:53")) : cb(tsplus_module_2.succeedNow(stats, fileName_1 + ":239:78")));
144
+ });
145
+ }
146
+ function mkdir(path, options) {
147
+ return tsplus_module_2.async((cb) => {
148
+ fs.mkdir(path, options, (err, path) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":248:61")) : cb(tsplus_module_2.succeed(() => tsplus_module_5.fromNullable(path), fileName_1 + ":248:83")));
149
+ });
150
+ }
151
+ function mkdtemp(prefix, options) {
152
+ return tsplus_module_2.async((cb) => {
153
+ fs.mkdtemp(prefix, options, (err, folder) => err ? cb(tsplus_module_2.failNow(err, fileName_1 + ":254:70")) : cb(tsplus_module_2.succeedNow(folder, fileName_1 + ":254:95")));
154
+ });
155
+ }
156
+ function open(path, flags, mode) {
157
+ return tsplus_module_2.async((cb) => {
158
+ fs.open(path, flags, mode ?? null, (err, fd) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":264:70")) : cb(tsplus_module_2.succeed(() => FileDescriptor.get(fd), fileName_1 + ":264:92")));
159
+ });
160
+ }
161
+ var Dir = class {
162
+ path;
163
+ _dir;
164
+ constructor(dir) {
165
+ this.path = dir.path;
166
+ this._dir = dir;
167
+ }
168
+ close() {
169
+ return tsplus_module_2.async((cb) => {
170
+ this._dir.close(unitErrorCallback(cb));
171
+ });
172
+ }
173
+ read() {
174
+ return tsplus_module_2.async((cb) => {
175
+ this._dir.read((err, dirEnt) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":284:56")) : cb(tsplus_module_2.succeedNow(tsplus_module_5.fromNullable(dirEnt), fileName_1 + ":284:81")));
176
+ });
177
+ }
178
+ };
179
+ function opendir(path, options) {
180
+ return tsplus_module_2.async((cb) => {
181
+ fs.opendir(path, options ?? {}, (err, dir) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":291:75")) : cb(tsplus_module_2.succeedNow(new Dir(dir), fileName_1 + ":291:100")));
182
+ });
183
+ }
184
+ function read(fd, length, position) {
185
+ return tsplus_module_2.async((cb) => {
186
+ const buf = Buffer.alloc(length);
187
+ fs.read(FileDescriptor.reverseGet(fd), buf, 0, length, position ?? null, (err, bytesRead, buffer) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":303:23")) : cb(tsplus_module_2.succeed(() => [bytesRead, buffer], fileName_1 + ":303:45")));
188
+ });
189
+ }
190
+ function readFile(file, options = {}) {
191
+ return tsplus_module_17.asyncInterrupt((cb) => {
192
+ const abortController = new AbortController();
193
+ fs.readFile(file, {
194
+ ...options,
195
+ signal: abortController.signal
196
+ }, (err, data) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":320:23")) : cb(tsplus_module_2.succeedNow(data, fileName_1 + ":320:48")));
197
+ return tsplus_module_16.left(tsplus_module_2.succeed(() => abortController.abort(), fileName_1 + ":322:34"), fileName_1 + ":322:23");
198
+ });
199
+ }
200
+ function readdir(path, options) {
201
+ return tsplus_module_2.async((cb) => {
202
+ fs.readdir(path, options ?? {}, (err, files) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":356:23")) : files[0] && files[0] instanceof fs.Dir ? files.map((a) => new Dir(a)) : files);
203
+ });
204
+ }
205
+ function realpath(path, options) {
206
+ return tsplus_module_2.async((cb) => {
207
+ fs.realpath(path, options ?? {}, (err, resolvedPath) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":375:78")) : cb(tsplus_module_2.succeedNow(resolvedPath, fileName_1 + ":375:103")));
208
+ });
209
+ }
210
+ function realpathNative(path, options) {
211
+ return tsplus_module_2.async((cb) => {
212
+ fs.realpath.native(path, options ?? {}, (err, resolvedPath) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":394:23")) : cb(tsplus_module_2.succeed(() => resolvedPath, fileName_1 + ":394:45")));
213
+ });
214
+ }
215
+ function rename(oldPath, newPath) {
216
+ return tsplus_module_2.async((cb) => {
217
+ fs.rename(oldPath, newPath, unitErrorCallback(cb));
218
+ });
219
+ }
220
+ function rm(path, options) {
221
+ return tsplus_module_2.async((cb) => {
222
+ fs.rm(path, options ?? {}, unitErrorCallback(cb));
223
+ });
224
+ }
225
+ function rmdir(path) {
226
+ return tsplus_module_2.async((cb) => {
227
+ fs.rmdir(path, unitErrorCallback(cb));
228
+ });
229
+ }
230
+ function stat(path, options) {
231
+ return tsplus_module_2.async((cb) => {
232
+ fs.stat(path, options ?? {}, (err, stats) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":424:76")) : cb(tsplus_module_2.succeedNow(stats, fileName_1 + ":424:101")));
233
+ });
234
+ }
235
+ function symlink(target, path) {
236
+ return tsplus_module_2.async((cb) => {
237
+ fs.symlink(target, path, unitErrorCallback(cb));
238
+ });
239
+ }
240
+ function truncate(path, len) {
241
+ return tsplus_module_2.async((cb) => {
242
+ fs.truncate(path, len, unitErrorCallback(cb));
243
+ });
244
+ }
245
+ function unlink(path) {
246
+ return tsplus_module_2.async((cb) => {
247
+ fs.unlink(path, unitErrorCallback(cb));
248
+ });
249
+ }
250
+ function utimes(path, atime, mtime) {
251
+ return tsplus_module_2.async((cb) => {
252
+ fs.utimes(path, atime, mtime, unitErrorCallback(cb));
253
+ });
254
+ }
255
+ function write(fd, buffer, position) {
256
+ return tsplus_module_2.async((cb) => {
257
+ const b = tsplus_module_18.toBuffer(buffer);
258
+ fs.write(FileDescriptor.reverseGet(fd), b, position ?? null, b.byteLength, (err, bytesWritten) => err ? cb(tsplus_module_2.failNow(err, fileName_1 + ":460:26")) : cb(tsplus_module_2.succeedNow(bytesWritten, fileName_1 + ":460:51")));
259
+ });
260
+ }
261
+ function writeFile(file, data, options = {}) {
262
+ return tsplus_module_17.asyncInterrupt((cb) => {
263
+ const abortController = new AbortController();
264
+ fs.writeFile(file, data, {
265
+ ...options,
266
+ signal: abortController.signal
267
+ }, (err) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":479:23")) : tsplus_module_2.unit);
268
+ return tsplus_module_16.left(tsplus_module_2.succeed(() => abortController.abort(), fileName_1 + ":481:34"), fileName_1 + ":481:23");
269
+ });
270
+ }
271
+ function writev(fd, buffers, position) {
272
+ return tsplus_module_2.async((cb) => {
273
+ if (position) fs.writev(FileDescriptor.reverseGet(fd), buffers, position, (err, bytesWritten) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":493:25")) : cb(tsplus_module_2.succeedNow(bytesWritten, fileName_1 + ":493:50")));
274
+ else fs.writev(FileDescriptor.reverseGet(fd), buffers, (err, bytesWritten) => err ? cb(tsplus_module_2.fail(() => err, fileName_1 + ":497:25")) : cb(tsplus_module_2.succeedNow(bytesWritten, fileName_1 + ":497:50")));
275
+ });
276
+ }
277
+ function watch(filename, options) {
278
+ return tsplus_module_7.flatMap((watcher) => tsplus_module_7.repeatIOMaybe(tsplus_module_2.async((cb) => {
279
+ watcher.once("change", (eventType, filename) => {
280
+ watcher.removeAllListeners();
281
+ cb(tsplus_module_2.succeedNow({
282
+ eventType,
283
+ filename
284
+ }, fileName_1 + ":533:27"));
285
+ });
286
+ watcher.once("error", (error) => {
287
+ watcher.removeAllListeners();
288
+ cb(tsplus_module_2.failNow(tsplus_module_5.just(error, fileName_1 + ":537:29"), fileName_1 + ":537:24"));
289
+ });
290
+ watcher.once("close", () => {
291
+ watcher.removeAllListeners();
292
+ cb(tsplus_module_2.failNow(tsplus_module_5.nothing(fileName_1 + ":541:32"), fileName_1 + ":541:24"));
293
+ });
294
+ }), fileName_1 + ":529:25"), fileName_1 + ":528:12")(tsplus_module_7.fromIO(tsplus_module_2.tryCatch(() => fs.watch(filename, options ?? {}), (err) => err, fileName_1 + ":524:16"), fileName_1 + ":523:23"));
295
+ }
296
+ function watchFile(filename, options) {
297
+ return tsplus_module_7.flatMap((queue) => tsplus_module_7.repeatIOMaybe(tsplus_module_19.take(queue, fileName_1 + ":578:50"), fileName_1 + ":578:44"), fileName_1 + ":578:12")(tsplus_module_7.acquireRelease(tsplus_module_2.flatMap((queue) => tsplus_module_2.map((runtime) => {
298
+ fs.watchFile(filename, options ?? {}, (curr, prev) => {
299
+ runtime.unsafeRunFiber(tsplus_module_19.offer([curr, prev], fileName_1 + ":573:43")(queue), fileName_1 + ":573:31");
300
+ });
301
+ return queue;
302
+ }, fileName_1 + ":571:24")(tsplus_module_20.runtime(fileName_1 + ":571:35")), fileName_1 + ":570:24")(tsplus_module_21.makeUnbounded(fileName_1 + ":570:44")), (queue) => tsplus_module_19.shutdown(queue, fileName_1 + ":577:21"), fileName_1 + ":568:31"));
303
+ }
304
+ //#endregion
305
+ export { Dir, FileDescriptor, access, appendFile, chmod, chown, close, copyFile, createReadStream, createWriteSink, fchmod, fchown, fdatasync, fstat, fsync, ftruncate, futimes, lchmod, lchown, link, lstat, lutimes, mkdir, mkdtemp, open, opendir, read, readFile, readdir, realpath, realpathNative, rename, rm, rmdir, stat, symlink, truncate, unlink, utimes, watch, watchFile, write, writeFile, writev };
306
+
311
307
  //# sourceMappingURL=api.mjs.map