cf-workers-native 0.1.4 → 0.1.6

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 (296) hide show
  1. package/README.md +2 -2
  2. package/dist/browser/documents/page-source.js +1 -1
  3. package/dist/browser/fetch/host-call.js +6 -1
  4. package/dist/browser/fetch/native-network.d.ts +1 -1
  5. package/dist/browser/fetch/relay.js +2 -0
  6. package/dist/browser/headers/index.d.ts +2 -0
  7. package/dist/browser/headers/index.js +5 -0
  8. package/dist/browser/isolated/transport.js +3 -2
  9. package/dist/browser/request/index.js +3 -2
  10. package/dist/browser/response/index.d.ts +2 -0
  11. package/dist/browser/response/index.js +11 -3
  12. package/dist/browser/structured-clone/index.d.ts +3 -0
  13. package/dist/browser/structured-clone/index.js +75 -7
  14. package/dist/browser/websocket/attachment-size.d.ts +3 -0
  15. package/dist/browser/websocket/attachment-size.js +336 -0
  16. package/dist/browser/websocket/brand.d.ts +4 -0
  17. package/dist/browser/websocket/brand.js +16 -0
  18. package/dist/browser/websocket/close-event.d.ts +7 -0
  19. package/dist/browser/websocket/close-event.js +30 -0
  20. package/dist/browser/websocket/compression.d.ts +5 -0
  21. package/dist/browser/websocket/compression.js +124 -0
  22. package/dist/browser/websocket/conversion.d.ts +2 -0
  23. package/dist/browser/websocket/conversion.js +13 -0
  24. package/dist/browser/websocket/endpoint.d.ts +39 -0
  25. package/dist/browser/websocket/endpoint.js +379 -0
  26. package/dist/browser/websocket/frames.d.ts +21 -0
  27. package/dist/browser/websocket/frames.js +121 -0
  28. package/dist/browser/websocket/native.d.ts +14 -0
  29. package/dist/browser/websocket/native.js +226 -0
  30. package/dist/cloudflare/apis/cloudflare-node/index.js +11 -23
  31. package/dist/cloudflare/workers/worker-runtime.js +2 -1
  32. package/dist/compat/console/index.d.ts +35 -0
  33. package/dist/compat/console/index.js +92 -0
  34. package/dist/compat/crypto/LICENSE-3RD-PARTY.md +39 -0
  35. package/dist/compat/crypto/LICENSE-APACHE +177 -0
  36. package/dist/compat/crypto/LICENSE.boringssl +238 -0
  37. package/dist/compat/crypto/LICENSE.emscripten +102 -0
  38. package/dist/compat/crypto/LICENSE.musl +193 -0
  39. package/dist/compat/crypto/LICENSE.ncrypto +21 -0
  40. package/dist/compat/crypto/LICENSE.openssl +177 -0
  41. package/dist/compat/crypto/asymmetric.d.ts +13 -0
  42. package/dist/compat/crypto/asymmetric.js +312 -0
  43. package/dist/compat/crypto/brorand.cjs +74 -0
  44. package/dist/compat/crypto/brorand.d.cts +6 -0
  45. package/dist/compat/crypto/certificate.d.ts +14 -0
  46. package/dist/compat/crypto/certificate.js +66 -0
  47. package/dist/compat/crypto/cipher-handle.d.ts +27 -0
  48. package/dist/compat/crypto/cipher-handle.js +239 -0
  49. package/dist/compat/crypto/cipher-info.d.ts +12 -0
  50. package/dist/compat/crypto/cipher-info.js +324 -0
  51. package/dist/compat/crypto/constants.d.ts +62 -0
  52. package/dist/compat/crypto/constants.js +68 -0
  53. package/dist/compat/crypto/dh-handle.d.ts +17 -0
  54. package/dist/compat/crypto/dh-handle.js +180 -0
  55. package/dist/compat/crypto/dh.d.ts +53 -0
  56. package/dist/compat/crypto/dh.js +138 -0
  57. package/dist/compat/crypto/digest-stream.d.ts +15 -0
  58. package/dist/compat/crypto/digest-stream.js +213 -0
  59. package/dist/compat/crypto/digests.d.ts +3 -0
  60. package/dist/compat/crypto/digests.js +32 -0
  61. package/dist/compat/crypto/ecdh.d.ts +25 -0
  62. package/dist/compat/crypto/ecdh.js +109 -0
  63. package/dist/compat/crypto/hash-handle.d.ts +23 -0
  64. package/dist/compat/crypto/hash-handle.js +70 -0
  65. package/dist/compat/crypto/hash.d.ts +37 -0
  66. package/dist/compat/crypto/hash.js +218 -0
  67. package/dist/compat/crypto/hkdf.d.ts +2 -0
  68. package/dist/compat/crypto/hkdf.js +78 -0
  69. package/dist/compat/crypto/index.cjs +2 -0
  70. package/dist/compat/crypto/index.d.cts +169 -0
  71. package/dist/compat/crypto/index.d.ts +213 -0
  72. package/dist/compat/crypto/index.js +96 -0
  73. package/dist/compat/crypto/key-errors.d.ts +10 -0
  74. package/dist/compat/crypto/key-errors.js +17 -0
  75. package/dist/compat/crypto/key-export.d.ts +8 -0
  76. package/dist/compat/crypto/key-export.js +49 -0
  77. package/dist/compat/crypto/key-formats.d.ts +7 -0
  78. package/dist/compat/crypto/key-formats.js +251 -0
  79. package/dist/compat/crypto/key-options.d.ts +1 -0
  80. package/dist/compat/crypto/key-options.js +74 -0
  81. package/dist/compat/crypto/key-state.d.ts +10 -0
  82. package/dist/compat/crypto/key-state.js +4 -0
  83. package/dist/compat/crypto/keys.d.ts +58 -0
  84. package/dist/compat/crypto/keys.js +278 -0
  85. package/dist/compat/crypto/metadata.d.ts +13 -0
  86. package/dist/compat/crypto/metadata.js +109 -0
  87. package/dist/compat/crypto/native-cipher.d.ts +17 -0
  88. package/dist/compat/crypto/native-cipher.js +192 -0
  89. package/dist/compat/crypto/native-crypto.d.ts +81 -0
  90. package/dist/compat/crypto/native-crypto.js +681 -0
  91. package/dist/compat/crypto/pbkdf2-handle.d.ts +4 -0
  92. package/dist/compat/crypto/pbkdf2-handle.js +26 -0
  93. package/dist/compat/crypto/pbkdf2.d.ts +5 -0
  94. package/dist/compat/crypto/pbkdf2.js +60 -0
  95. package/dist/compat/crypto/prime.d.ts +19 -0
  96. package/dist/compat/crypto/prime.js +146 -0
  97. package/dist/compat/crypto/random.d.ts +18 -0
  98. package/dist/compat/crypto/random.js +203 -0
  99. package/dist/compat/crypto/rsa.d.ts +21 -0
  100. package/dist/compat/crypto/rsa.js +177 -0
  101. package/dist/compat/crypto/scrypt.d.ts +25 -0
  102. package/dist/compat/crypto/scrypt.js +152 -0
  103. package/dist/compat/crypto/sign-errors.d.ts +8 -0
  104. package/dist/compat/crypto/sign-errors.js +13 -0
  105. package/dist/compat/crypto/sign-handle.d.ts +22 -0
  106. package/dist/compat/crypto/sign-handle.js +149 -0
  107. package/dist/compat/crypto/signatures.d.ts +34 -0
  108. package/dist/compat/crypto/signatures.js +252 -0
  109. package/dist/compat/crypto/subtle-digest.d.ts +1 -0
  110. package/dist/compat/crypto/subtle-digest.js +56 -0
  111. package/dist/compat/crypto/symmetric.d.ts +45 -0
  112. package/dist/compat/crypto/symmetric.js +239 -0
  113. package/dist/compat/crypto/validation.d.ts +7 -0
  114. package/dist/compat/crypto/validation.js +46 -0
  115. package/dist/compat/crypto/webcrypto.d.ts +13 -0
  116. package/dist/compat/crypto/webcrypto.js +51 -0
  117. package/dist/compat/crypto/x509.d.ts +30 -0
  118. package/dist/compat/crypto/x509.js +407 -0
  119. package/dist/compat/events/errors.d.ts +8 -0
  120. package/dist/compat/events/errors.js +39 -0
  121. package/dist/compat/events/index.cjs +2 -0
  122. package/dist/compat/events/index.d.cts +2 -0
  123. package/dist/compat/events/index.d.ts +64 -0
  124. package/dist/compat/events/index.js +792 -0
  125. package/dist/compat/events/intrinsics.d.ts +1 -0
  126. package/dist/compat/events/intrinsics.js +2 -0
  127. package/dist/compat/fs/LICENSE-3RD-PARTY.md +11 -0
  128. package/dist/compat/fs/LICENSE-APACHE +177 -0
  129. package/dist/compat/fs/directory-backend.d.ts +6 -0
  130. package/dist/compat/fs/directory-backend.js +51 -0
  131. package/dist/compat/fs/directory.d.ts +37 -0
  132. package/dist/compat/fs/directory.js +137 -0
  133. package/dist/compat/fs/embedded.d.ts +85 -0
  134. package/dist/compat/fs/embedded.js +260 -0
  135. package/dist/compat/fs/file-handle.d.ts +75 -0
  136. package/dist/compat/fs/file-handle.js +226 -0
  137. package/dist/compat/fs/glob-internal.d.ts +15 -0
  138. package/dist/compat/fs/glob-internal.js +417 -0
  139. package/dist/compat/fs/glob.d.ts +10 -0
  140. package/dist/compat/fs/glob.js +71 -0
  141. package/dist/compat/fs/index.d.ts +8 -82
  142. package/dist/compat/fs/index.js +736 -238
  143. package/dist/compat/fs/io-validation.d.ts +14 -0
  144. package/dist/compat/fs/io-validation.js +130 -0
  145. package/dist/compat/fs/io.d.ts +1 -0
  146. package/dist/compat/fs/io.js +282 -0
  147. package/dist/compat/fs/mode.d.ts +1 -0
  148. package/dist/compat/fs/mode.js +13 -0
  149. package/dist/compat/fs/promises/index.d.ts +3 -1
  150. package/dist/compat/fs/promises/index.js +1 -1
  151. package/dist/compat/fs/public-types.d.ts +120 -0
  152. package/dist/compat/fs/public-types.js +1 -0
  153. package/dist/compat/fs/stream-errors.d.ts +6 -0
  154. package/dist/compat/fs/stream-errors.js +8 -0
  155. package/dist/compat/fs/stream-utils.d.ts +16 -0
  156. package/dist/compat/fs/stream-utils.js +29 -0
  157. package/dist/compat/fs/streams.d.ts +104 -0
  158. package/dist/compat/fs/streams.js +794 -0
  159. package/dist/compat/fs/writable.d.ts +14 -0
  160. package/dist/compat/fs/writable.js +532 -0
  161. package/dist/compat/http/index.d.ts +11 -28
  162. package/dist/compat/http/index.js +81 -125
  163. package/dist/compat/http/server-options.d.ts +1 -0
  164. package/dist/compat/http/server-options.js +87 -0
  165. package/dist/compat/http/symbols.d.ts +5 -0
  166. package/dist/compat/http/symbols.js +9 -0
  167. package/dist/compat/http/unique-headers.d.ts +1 -0
  168. package/dist/compat/http/unique-headers.js +21 -0
  169. package/dist/compat/http-common/index.d.ts +37 -0
  170. package/dist/compat/http-common/index.js +43 -0
  171. package/dist/compat/http-outgoing/index.d.ts +14 -0
  172. package/dist/compat/http-outgoing/index.js +17 -0
  173. package/dist/compat/http-server/index.d.ts +18 -0
  174. package/dist/compat/http-server/index.js +26 -0
  175. package/dist/compat/https/index.d.ts +4 -2
  176. package/dist/compat/module/builtins.d.ts +1 -0
  177. package/dist/compat/module/builtins.js +101 -0
  178. package/dist/compat/module/index.d.ts +4 -2
  179. package/dist/compat/module/index.js +22 -17
  180. package/dist/compat/module/metadata.d.ts +44 -0
  181. package/dist/compat/module/metadata.js +127 -0
  182. package/dist/compat/net/internal-net.js +4 -0
  183. package/dist/compat/net/sockets.d.ts +5 -0
  184. package/dist/compat/net/sockets.js +153 -14
  185. package/dist/compat/net/validators.d.ts +1 -0
  186. package/dist/compat/net/validators.js +8 -0
  187. package/dist/compat/process/configuration.d.ts +113 -0
  188. package/dist/compat/process/configuration.js +115 -0
  189. package/dist/compat/process/directory.d.ts +4 -0
  190. package/dist/compat/process/directory.js +28 -0
  191. package/dist/compat/process/files.d.ts +3 -0
  192. package/dist/compat/process/files.js +10 -0
  193. package/dist/compat/process/index.cjs +2 -0
  194. package/dist/compat/process/index.d.cts +4 -0
  195. package/dist/compat/process/index.d.ts +20 -0
  196. package/dist/compat/process/index.js +113 -0
  197. package/dist/compat/process/metadata.d.ts +135 -0
  198. package/dist/compat/process/metadata.js +251 -0
  199. package/dist/compat/process/scheduling.d.ts +2 -0
  200. package/dist/compat/process/scheduling.js +60 -0
  201. package/dist/compat/process/state.d.ts +4 -0
  202. package/dist/compat/process/state.js +5 -0
  203. package/dist/compat/process/stdio.d.ts +18 -0
  204. package/dist/compat/process/stdio.js +66 -0
  205. package/dist/compat/stream/destroy.d.ts +1 -0
  206. package/dist/compat/stream/destroy.js +21 -1
  207. package/dist/compat/stream/readable.js +10 -2
  208. package/dist/compat/stream-web/LICENSE +22 -0
  209. package/dist/compat/stream-web/ponyfill.d.ts +1 -1
  210. package/dist/compat/stream-web/ponyfill.js +2369 -1775
  211. package/dist/compat/stream-web/runtime.d.ts +1 -1
  212. package/dist/compat/stream-web/runtime.js +3 -2
  213. package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
  214. package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
  215. package/dist/compat/stream-wrap/index.d.ts +1 -0
  216. package/dist/compat/stream-wrap/index.js +1 -0
  217. package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
  218. package/dist/compat/tls/LICENSE-APACHE +177 -0
  219. package/dist/compat/tls/constants.d.ts +7 -0
  220. package/dist/compat/tls/constants.js +14 -0
  221. package/dist/compat/tls/errors.d.ts +35 -0
  222. package/dist/compat/tls/errors.js +68 -0
  223. package/dist/compat/tls/helpers.d.ts +9 -0
  224. package/dist/compat/tls/helpers.js +207 -0
  225. package/dist/compat/tls/index.d.ts +26 -0
  226. package/dist/compat/tls/index.js +50 -0
  227. package/dist/compat/tls/jsstream.d.ts +19 -0
  228. package/dist/compat/tls/jsstream.js +196 -0
  229. package/dist/compat/tls/native-session.d.ts +3 -0
  230. package/dist/compat/tls/native-session.js +187 -0
  231. package/dist/compat/tls/wrap.d.ts +65 -0
  232. package/dist/compat/tls/wrap.js +541 -0
  233. package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
  234. package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
  235. package/dist/compat/tls-wrap/index.d.ts +7 -0
  236. package/dist/compat/tls-wrap/index.js +3 -0
  237. package/dist/compat/util/index.js +43 -1
  238. package/dist/compat/util/inspect.js +5 -1
  239. package/dist/compat/util/types/index.d.ts +3 -0
  240. package/dist/compat/util/types/index.js +5 -0
  241. package/dist/compat/zlib/LICENSE-3RD-PARTY.md +11 -0
  242. package/dist/compat/zlib/LICENSE-APACHE +177 -0
  243. package/dist/compat/zlib/LICENSE.brotli +19 -0
  244. package/dist/compat/zlib/LICENSE.emscripten +102 -0
  245. package/dist/compat/zlib/LICENSE.musl +193 -0
  246. package/dist/compat/zlib/LICENSE.zlib +22 -0
  247. package/dist/compat/zlib/LICENSE.zstd +30 -0
  248. package/dist/compat/zlib/classic-base.cjs +600 -0
  249. package/dist/compat/zlib/classic-base.d.cts +39 -0
  250. package/dist/compat/zlib/classic-binding.d.ts +28 -0
  251. package/dist/compat/zlib/classic-binding.js +105 -0
  252. package/dist/compat/zlib/classic.d.ts +44 -0
  253. package/dist/compat/zlib/classic.js +199 -0
  254. package/dist/compat/zlib/codec-binding.d.ts +33 -0
  255. package/dist/compat/zlib/codec-binding.js +141 -0
  256. package/dist/compat/zlib/compression.d.ts +26 -0
  257. package/dist/compat/zlib/compression.js +170 -0
  258. package/dist/compat/zlib/constants.d.ts +172 -0
  259. package/dist/compat/zlib/constants.js +173 -0
  260. package/dist/compat/zlib/errors.d.ts +21 -0
  261. package/dist/compat/zlib/errors.js +32 -0
  262. package/dist/compat/zlib/index.d.ts +544 -0
  263. package/dist/compat/zlib/index.js +194 -0
  264. package/dist/compat/zlib/input.d.ts +16 -0
  265. package/dist/compat/zlib/input.js +132 -0
  266. package/dist/compat/zlib/native-codecs.d.ts +24 -0
  267. package/dist/compat/zlib/native-codecs.js +180 -0
  268. package/dist/compat/zlib/native-zlib.d.ts +5 -0
  269. package/dist/compat/zlib/native-zlib.js +52 -0
  270. package/dist/compat/zlib/public-types.d.ts +48 -0
  271. package/dist/compat/zlib/public-types.js +1 -0
  272. package/dist/compat/zlib/validators.d.ts +3 -0
  273. package/dist/compat/zlib/validators.js +18 -0
  274. package/dist/shared/buffer-source.d.ts +5 -0
  275. package/dist/shared/buffer-source.js +70 -0
  276. package/dist/shared/globals/inject.d.ts +2 -1
  277. package/dist/shared/globals/inject.js +2 -1
  278. package/dist/shared/globals/platform.d.ts +8 -0
  279. package/dist/shared/globals/platform.js +1 -0
  280. package/dist/shared/globals/runtime.d.ts +1 -2
  281. package/dist/shared/globals/runtime.js +1 -2
  282. package/dist/shared/globals/web.js +5 -0
  283. package/dist/shared/request-context.d.ts +2 -0
  284. package/dist/shared/request-context.js +11 -0
  285. package/dist/shared/request-scope.d.ts +4 -0
  286. package/dist/shared/request-scope.js +14 -0
  287. package/dist/tooling/async.js +36 -14
  288. package/dist/tooling/shared.d.ts +1 -0
  289. package/dist/tooling/shared.js +26 -1
  290. package/dist/tooling/vite.js +8 -3
  291. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +92 -13
  292. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
  293. package/native/ios/NetworkBridge.swift +11 -1
  294. package/native/ios/SocketBridge.swift +37 -2
  295. package/native/ios/WorkersCapacitorPlugin.swift +4 -0
  296. package/package.json +4 -2
@@ -0,0 +1,14 @@
1
+ import { Buffer } from "node:buffer";
2
+ export declare function getValidatedFd(fd: any): number;
3
+ export declare function validatePosition(position: any, name: any): void;
4
+ export declare function validateWriteArgs(fd: number, buffer: NodeJS.ArrayBufferView | string, offsetOrOptions: WriteSyncOptions | Position | undefined, length: number | ValidEncoding | undefined, position: Position | undefined): {
5
+ fd: number;
6
+ buffer: Buffer[];
7
+ position: Position;
8
+ };
9
+ export declare function validateReadArgs(fd: number, buffer: NodeJS.ArrayBufferView, offsetOrOptions: ReadOptions | number | null, length: number | undefined, position: Position | undefined): {
10
+ fd: number;
11
+ buffer: Buffer[];
12
+ length: number;
13
+ position: Position;
14
+ };
@@ -0,0 +1,130 @@
1
+ // @ts-nocheck
2
+ // Adapted from cloudflare/workerd@5358e3d337336eaf696a48bc1563d808b10feba5.
3
+ // Copyright Cloudflare, Inc. Licensed under Apache-2.0; see LICENSE-APACHE.
4
+ import { Buffer } from "node:buffer";
5
+ import { validateInteger } from "../crypto/validation.js";
6
+ import { validateUint32 } from "../net/validators.js";
7
+ import { ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, ERR_OUT_OF_RANGE, } from "../net/errors.js";
8
+ const isArrayBufferView = ArrayBuffer.isView;
9
+ class ERR_BUFFER_OUT_OF_BOUNDS extends RangeError {
10
+ code = "ERR_BUFFER_OUT_OF_BOUNDS";
11
+ constructor(name) {
12
+ super(`${name} is outside of buffer bounds`);
13
+ }
14
+ }
15
+ function validateEncoding(value, encoding) {
16
+ if (encoding !== undefined && !Buffer.isEncoding(encoding))
17
+ throw new ERR_INVALID_ARG_VALUE("encoding", encoding);
18
+ }
19
+ export function getValidatedFd(fd) {
20
+ validateInteger(fd, "fd", 0, 2147483647);
21
+ return fd;
22
+ }
23
+ export function validatePosition(position, name) {
24
+ if (typeof position === "number")
25
+ validateUint32(position, name);
26
+ else if (typeof position !== "bigint" && position !== null)
27
+ throw new ERR_INVALID_ARG_TYPE(name, ["integer", "bigint", "null"], position);
28
+ }
29
+ export function validateWriteArgs(fd, buffer, offsetOrOptions, length, position) {
30
+ fd = getValidatedFd(fd);
31
+ let offset = offsetOrOptions;
32
+ if (isArrayBufferView(buffer)) {
33
+ if (typeof offsetOrOptions === "object" && offsetOrOptions != null) {
34
+ ({
35
+ offset = 0,
36
+ length,
37
+ position = null,
38
+ } = offsetOrOptions);
39
+ offset ??= 0;
40
+ validateInteger(offset, "offset", 0);
41
+ }
42
+ else {
43
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
44
+ if (offset != null) {
45
+ validateInteger(offset, "offset", 0);
46
+ }
47
+ offset ??= 0;
48
+ position ??= null;
49
+ }
50
+ validatePosition(position, "position");
51
+ if (offset > buffer.byteLength) {
52
+ throw new ERR_BUFFER_OUT_OF_BOUNDS("offset");
53
+ }
54
+ length ??= buffer.byteLength - offset;
55
+ validateInteger(length, "length", 0);
56
+ if (length > buffer.byteLength - offset) {
57
+ throw new ERR_BUFFER_OUT_OF_BOUNDS("length");
58
+ }
59
+ return {
60
+ fd,
61
+ buffer: [Buffer.from(buffer.buffer, buffer.byteOffset + offset, length)],
62
+ position,
63
+ };
64
+ }
65
+ if (typeof buffer !== "string") {
66
+ throw new ERR_INVALID_ARG_TYPE("buffer", ["string", "Buffer", "TypedArray", "DataView"], buffer);
67
+ }
68
+ // In this case, offsetOrOptions must either be a number, bigint, or null.
69
+ validatePosition(offsetOrOptions, "position");
70
+ position = offsetOrOptions;
71
+ // In this instance, buffer is a string and the length arg specifies
72
+ // the encoding to use.
73
+ validateEncoding(buffer, length);
74
+ return {
75
+ fd,
76
+ buffer: [Buffer.from(buffer, length /* encoding */)],
77
+ position,
78
+ };
79
+ }
80
+ export function validateReadArgs(fd, buffer, offsetOrOptions, length, position) {
81
+ fd = getValidatedFd(fd);
82
+ // Great fun with polymorphism here. We're going to normalize the arguments
83
+ // to match the first signature (fd, buffer, offset, length, position).
84
+ //
85
+ // If the third argument is an object, then we will pull the offset, length,
86
+ // and position from it, ignoring the remaining arguments. If the third
87
+ // argument is a number, then we will use it as the offset and pull the
88
+ // length and position from the fourth and fifth arguments. If the third
89
+ // position is any other type, then we will throw an error.
90
+ if (!isArrayBufferView(buffer)) {
91
+ throw new ERR_INVALID_ARG_TYPE("buffer", ["Buffer", "TypedArray", "DataView"], buffer);
92
+ }
93
+ let actualOffset;
94
+ let actualLength;
95
+ let actualPosition = position;
96
+ // Handle the case where the third argument is an options object
97
+ if (offsetOrOptions != null && typeof offsetOrOptions === "object") {
98
+ const { offset = 0, length = buffer.byteLength - offset, position = null, } = offsetOrOptions;
99
+ actualOffset = offset;
100
+ actualLength = length;
101
+ actualPosition = position;
102
+ }
103
+ // Handle the case where the third argument is a number (offset)
104
+ else if (typeof offsetOrOptions === "number") {
105
+ actualOffset = offsetOrOptions;
106
+ actualLength = length ?? buffer.byteLength - offsetOrOptions;
107
+ actualPosition = position;
108
+ }
109
+ else {
110
+ throw new ERR_INVALID_ARG_TYPE("offset", ["number", "object"], offsetOrOptions);
111
+ }
112
+ validateUint32(actualOffset, "offset");
113
+ validateUint32(actualLength, "length");
114
+ validatePosition(actualPosition, "position");
115
+ // As in Node, a zero-length read is a no-op regardless of offset.
116
+ if (actualLength === 0) {
117
+ return { fd, buffer: [], length: 0, position: actualPosition };
118
+ }
119
+ if (actualOffset + actualLength > buffer.byteLength) {
120
+ throw new ERR_OUT_OF_RANGE("length", `<= ${buffer.byteLength - actualOffset}`, actualLength);
121
+ }
122
+ return {
123
+ fd,
124
+ buffer: [
125
+ Buffer.from(buffer.buffer, buffer.byteOffset + actualOffset, actualLength),
126
+ ],
127
+ length: actualLength,
128
+ position: actualPosition,
129
+ };
130
+ }
@@ -0,0 +1 @@
1
+ export declare function installIo(api: any, promises: any): void;
@@ -0,0 +1,282 @@
1
+ import { viewBytes } from "../../shared/buffer-source.js";
2
+ import { Buffer } from "node:buffer";
3
+ import { pathOf, descriptorFlags, readDescriptor } from "./writable.js";
4
+ import { fileMode } from "./mode.js";
5
+ import { validateWriteArgs, validateReadArgs, getValidatedFd, validatePosition, } from "./io-validation.js";
6
+ import { validateBoolean, validateObject, validateFunction, validateUint32, } from "../net/validators.js";
7
+ import { ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE } from "../net/errors.js";
8
+ export function installIo(api, promises) {
9
+ const raw = { ...api };
10
+ const fail = (code, message = code) => {
11
+ throw Object.assign(new Error(message), { code });
12
+ };
13
+ const perform = (fn) => {
14
+ try {
15
+ return fn();
16
+ }
17
+ catch (e) {
18
+ if (e.code === "EBADF")
19
+ e.message = "bad file descriptor";
20
+ throw e;
21
+ }
22
+ };
23
+ const install = (name, prepare, action, extra) => {
24
+ api[name + "Sync"] = (...args) => perform(() => action(...prepare(...args)));
25
+ api[name] = (...args) => {
26
+ const callback = typeof args.at(-1) === "function" ? args.pop() : undefined;
27
+ if (name === "read")
28
+ validateFunction(callback, "callback");
29
+ const prepared = prepare(...args);
30
+ validateFunction(callback, "callback");
31
+ let error, value;
32
+ try {
33
+ value = perform(() => action(...prepared));
34
+ }
35
+ catch (cause) {
36
+ error = cause;
37
+ }
38
+ queueMicrotask(() => callback(error ?? null, value, ...(extra?.(args) ?? [])));
39
+ };
40
+ if (Object.hasOwn(promises, name))
41
+ promises[name] = async (...args) => {
42
+ const result = api[name + "Sync"](...args);
43
+ // Workers' whole-file promise writers resolve without a value, unlike
44
+ // their synchronous counterparts and FileHandle.writeFile.
45
+ return name === "writeFile" || name === "appendFile"
46
+ ? undefined
47
+ : result;
48
+ };
49
+ };
50
+ const flags = (flag) => {
51
+ if (typeof flag === "number") {
52
+ validateUint32(flag, "flags");
53
+ return flag;
54
+ }
55
+ const value = {
56
+ r: 0,
57
+ "r+": 2,
58
+ rs: 1052672,
59
+ sr: 1052672,
60
+ "rs+": 1052674,
61
+ "sr+": 1052674,
62
+ w: 577,
63
+ wx: 705,
64
+ xw: 705,
65
+ "w+": 578,
66
+ "wx+": 706,
67
+ "xw+": 706,
68
+ a: 1089,
69
+ ax: 1217,
70
+ xa: 1217,
71
+ "a+": 1090,
72
+ "ax+": 1218,
73
+ "xa+": 1218,
74
+ as: 1053761,
75
+ sa: 1053761,
76
+ "as+": 1053762,
77
+ "sa+": 1053762,
78
+ };
79
+ if (!Object.hasOwn(value, flag))
80
+ throw new ERR_INVALID_ARG_VALUE("flags", flag);
81
+ return value[flag];
82
+ };
83
+ install("close", (fd) => [getValidatedFd(fd)], (fd) => {
84
+ try {
85
+ raw.closeSync(fd);
86
+ }
87
+ catch (e) {
88
+ if (e.code !== "EBADF")
89
+ throw e;
90
+ }
91
+ });
92
+ for (const name of ["truncate", "ftruncate"])
93
+ install(name, (path, length = 0) => {
94
+ validateUint32(length, "len");
95
+ return [
96
+ name === "ftruncate" ? getValidatedFd(path) : pathOf(path),
97
+ length,
98
+ ];
99
+ }, (...args) => raw[name + "Sync"](...args));
100
+ for (const name of ["write", "read"])
101
+ install(name, (fd, buffer, offset = name === "read" ? 0 : null, length, position = null) => {
102
+ const result = (name === "write" ? validateWriteArgs : validateReadArgs)(fd, buffer, offset, length, position);
103
+ return [result.fd, result.buffer, result.position];
104
+ }, (fd, buffers, position) => {
105
+ if (typeof position === "bigint") {
106
+ if (position < 0n || position > 0xffffffffn)
107
+ fail("EINVAL");
108
+ position = Number(position);
109
+ }
110
+ if (!buffers.length)
111
+ return 0;
112
+ return perform(() => raw[name + "Sync"](fd, buffers[0], 0, buffers[0].byteLength, position));
113
+ }, (args) => [args[1]]);
114
+ const writeCallback = api.write;
115
+ api.write = (...args) => {
116
+ if (typeof args[1] === "string" &&
117
+ args[2] !== null &&
118
+ typeof args[2] === "object")
119
+ args[2] = args[2].position ?? null;
120
+ return writeCallback(...args);
121
+ };
122
+ for (const name of ["readv", "writev"])
123
+ install(name, (fd, buffers, position = null) => {
124
+ getValidatedFd(fd);
125
+ validatePosition(position, "position");
126
+ if (!Array.isArray(buffers) ||
127
+ buffers.some((b) => !ArrayBuffer.isView(b)))
128
+ throw new ERR_INVALID_ARG_TYPE("buffers", "ArrayBufferView[]", buffers);
129
+ return [fd, buffers, position];
130
+ }, (fd, buffers, position) => {
131
+ let count = 0;
132
+ for (const buffer of buffers) {
133
+ const size = api[name === "readv" ? "readSync" : "writeSync"](fd, buffer, 0, buffer.byteLength, position === null ? null : Number(position) + count);
134
+ count += size;
135
+ }
136
+ return count;
137
+ }, (args) => [args[1]]);
138
+ const optionsObject = (options) => typeof options === "string" || options == null
139
+ ? { encoding: options }
140
+ : options;
141
+ install("readFile", (path, options = {}) => {
142
+ options = optionsObject(options);
143
+ validateObject(options, "options");
144
+ const { encoding = null, flag = "r" } = options;
145
+ flags(flag);
146
+ if (encoding !== null &&
147
+ encoding !== "buffer" &&
148
+ !Buffer.isEncoding(encoding))
149
+ throw new ERR_INVALID_ARG_VALUE("options.encoding", encoding);
150
+ return [
151
+ typeof path === "number" ? getValidatedFd(path) : pathOf(path),
152
+ encoding,
153
+ ];
154
+ }, (path, encoding) => {
155
+ let data;
156
+ try {
157
+ data =
158
+ typeof path === "number"
159
+ ? readDescriptor(path)
160
+ : raw.readFileSync(path);
161
+ }
162
+ catch (error) {
163
+ if (typeof path === "string" && error?.code === "ENOENT") {
164
+ throw Object.assign(new Error(`no such file or directory, readAll '${path}'`), {
165
+ code: "ENOENT",
166
+ errno: -2,
167
+ syscall: "readAll",
168
+ path,
169
+ });
170
+ }
171
+ throw error;
172
+ }
173
+ return typeof encoding === "string" ? data.toString(encoding) : data;
174
+ });
175
+ for (const name of ["writeFile", "appendFile"])
176
+ install(name, (path, data, options = {}) => {
177
+ path = typeof path === "number" ? getValidatedFd(path) : pathOf(path);
178
+ options = optionsObject(options);
179
+ validateObject(options, "options");
180
+ const { encoding = "utf8", mode = 0o666, flag = name === "appendFile" ? "a" : "w", flush = false, } = options;
181
+ if (encoding !== "buffer" && !Buffer.isEncoding(encoding))
182
+ throw new ERR_INVALID_ARG_VALUE("options.encoding", encoding);
183
+ validateBoolean(flush, "options.flush");
184
+ fileMode(mode);
185
+ const value = flags(flag);
186
+ if (!(value & 3) && !(value & 1024))
187
+ throw new ERR_INVALID_ARG_VALUE("flag", flag, "must indicate write or append");
188
+ if (typeof data === "string")
189
+ data = Buffer.from(data, encoding);
190
+ if (!ArrayBuffer.isView(data))
191
+ throw new ERR_INVALID_ARG_TYPE("data", ["string", "Buffer", "TypedArray", "DataView"], data);
192
+ return [
193
+ path,
194
+ Buffer.from(viewBytes(data)),
195
+ Boolean(value & 1024),
196
+ Boolean(value & 128),
197
+ ];
198
+ }, (path, data, append, exclusive) => {
199
+ if (typeof path !== "number") {
200
+ if (exclusive && api.existsSync(path))
201
+ fail("EEXIST");
202
+ raw[append ? "appendFileSync" : "writeFileSync"](path, data);
203
+ return data.length;
204
+ }
205
+ append ||= Boolean(descriptorFlags(path) & 1024);
206
+ if (!append)
207
+ api.ftruncateSync(path, 0);
208
+ return api.writeSync(path, data, 0, data.length, append ? api.fstatSync(path).size : 0);
209
+ });
210
+ // The callback frontends have their own pinned validation/default order.
211
+ api.readFile = (path, options, callback) => {
212
+ if (typeof options === "function") {
213
+ callback = options;
214
+ options = {};
215
+ }
216
+ options = optionsObject(options);
217
+ validateObject(options, "options");
218
+ const { encoding = null } = options;
219
+ if (encoding !== null &&
220
+ encoding !== "buffer" &&
221
+ !Buffer.isEncoding(encoding))
222
+ throw new ERR_INVALID_ARG_VALUE("options.encoding", encoding);
223
+ validateFunction(callback, "callback");
224
+ try {
225
+ const value = api.readFileSync(path, options);
226
+ queueMicrotask(() => callback(null, value));
227
+ }
228
+ catch (error) {
229
+ queueMicrotask(() => callback(error));
230
+ }
231
+ };
232
+ api.appendFile = (path, data, options, callback) => {
233
+ if (typeof options === "function") {
234
+ callback = options;
235
+ options = { encoding: "utf8", mode: 0o666, flag: "a", flush: false };
236
+ }
237
+ return api.writeFile(path, data, options, callback);
238
+ };
239
+ const open = api.openSync;
240
+ api.openSync = (path, flag = "r", mode) => {
241
+ let value = flags(flag);
242
+ if (!(value & 3))
243
+ value &= ~512;
244
+ return open(path, value, mode);
245
+ };
246
+ api.constants = Object.assign(Object.create(null), api.constants);
247
+ for (const name of [
248
+ "UV_FS_COPYFILE_EXCL",
249
+ "UV_FS_COPYFILE_FICLONE",
250
+ "UV_FS_COPYFILE_FICLONE_FORCE",
251
+ ])
252
+ api.constants[name] = api.constants[name.slice(6)];
253
+ promises.constants = api.constants;
254
+ const rename = api.renameSync;
255
+ install("rename", (src, dst) => [pathOf(src), pathOf(dst)], (src, dst) => {
256
+ if (src === dst)
257
+ return;
258
+ const stat = api.lstatSync(src);
259
+ const target = api.lstatSync(dst, { throwIfNoEntry: false });
260
+ if (stat.isDirectory()) {
261
+ if (dst.startsWith(src + "/"))
262
+ fail("EINVAL");
263
+ if (target && !target.isDirectory())
264
+ fail("ENOTDIR");
265
+ if (target && api.readdirSync(dst).length)
266
+ fail("ENOTEMPTY");
267
+ }
268
+ else if (target?.isDirectory())
269
+ fail("EISDIR");
270
+ return rename(src, dst);
271
+ });
272
+ const copy = api.copyFileSync;
273
+ install("copyFile", (src, dst, mode = 0) => {
274
+ src = pathOf(src);
275
+ dst = pathOf(dst);
276
+ if (![0, 1, 2, 4].includes(mode))
277
+ throw new ERR_INVALID_ARG_VALUE("mode", mode);
278
+ if (mode === 4)
279
+ fail("ERR_UNSUPPORTED_OPERATION", "The requested operation is unsupported");
280
+ return [src, dst, mode];
281
+ }, copy);
282
+ }
@@ -0,0 +1 @@
1
+ export declare function fileMode(value: unknown, fallback?: number): number;
@@ -0,0 +1,13 @@
1
+ // Pinned Workers mode validation (node/internal/validators.ts).
2
+ import { validateUint32 } from "../net/validators.js";
3
+ import { ERR_INVALID_ARG_VALUE } from "../net/errors.js";
4
+ export function fileMode(value, fallback) {
5
+ value ??= fallback;
6
+ if (typeof value === "string") {
7
+ if (!/^[0-7]+$/.test(value))
8
+ throw new ERR_INVALID_ARG_VALUE("mode", value, "must be a 32-bit unsigned integer or an octal string");
9
+ value = Number.parseInt(value, 8);
10
+ }
11
+ validateUint32(value, "mode");
12
+ return value;
13
+ }
@@ -1,3 +1,5 @@
1
1
  import { promises } from "../index.js";
2
- export declare const readFile: (path: unknown, options?: unknown) => Promise<unknown>, readdir: (path: unknown) => Promise<string[]>, stat: (path: unknown) => Promise<import("../index.js").Stats>, lstat: (path: unknown) => Promise<import("../index.js").Stats>, realpath: (path: unknown) => Promise<string>, access: (path: unknown) => Promise<void>;
2
+ export declare const FileHandle: typeof import("../file-handle.js").FileHandle, access: typeof import("node:fs/promises").access, appendFile: (path: import("../public-types.js").FileLocation, data: import("../public-types.js").FileData, options?: BufferEncoding | import("../public-types.js").WriteFileOptions) => Promise<void>, chmod: typeof import("node:fs/promises").chmod, chown: typeof import("node:fs/promises").chown, constants: typeof import("node:fs").constants, copyFile: typeof import("node:fs/promises").copyFile, cp: (source: import("../stream-utils.js").FilePath, destination: import("../stream-utils.js").FilePath, options?: import("node:fs").CopySyncOptions) => Promise<void>, glob: import("../public-types.js").Glob, lchmod: typeof import("node:fs/promises").lchmod, lchown: typeof import("node:fs/promises").lchown, link: typeof import("node:fs/promises").link, lstat: import("../public-types.js").Stat, lutimes: typeof import("node:fs/promises").lutimes, mkdir: (path: import("../stream-utils.js").FilePath, options?: number | import("node:fs").MakeDirectoryOptions) => Promise<string | undefined>, mkdtemp: (prefix: import("../stream-utils.js").FilePath, options?: BufferEncoding | "buffer" | {
3
+ encoding?: BufferEncoding | "buffer";
4
+ }) => Promise<string>, open: (path: import("../stream-utils.js").FilePath, flags?: string | number, mode?: import("node:fs").Mode) => Promise<import("../file-handle.js").FileHandle>, opendir: (path: import("../stream-utils.js").FilePath, options?: import("node:fs").OpenDirOptions) => Promise<import("../directory.js").Dir>, readFile: import("../public-types.js").ReadFile, readdir: import("../public-types.js").ReadDirectory, readlink: typeof import("node:fs/promises").readlink, realpath: typeof import("node:fs/promises").realpath, rename: typeof import("node:fs/promises").rename, rm: typeof import("node:fs/promises").rm, rmdir: typeof import("node:fs/promises").rmdir, stat: import("../public-types.js").Stat, statfs: typeof import("node:fs/promises").statfs, symlink: (target: import("../stream-utils.js").FilePath, path: import("../stream-utils.js").FilePath, type?: "dir" | "file" | "junction" | null) => Promise<void>, truncate: typeof import("node:fs/promises").truncate, unlink: typeof import("node:fs/promises").unlink, utimes: typeof import("node:fs/promises").utimes, watch: (...args: unknown[]) => never, writeFile: (path: import("../public-types.js").FileLocation, data: import("../public-types.js").FileData, options?: BufferEncoding | import("../public-types.js").WriteFileOptions) => Promise<void>;
3
5
  export default promises;
@@ -1,3 +1,3 @@
1
1
  import { promises } from "../index.js";
2
- export const { readFile, readdir, stat, lstat, realpath, access } = promises;
2
+ export const { FileHandle, access, appendFile, chmod, chown, constants, copyFile, cp, glob, lchmod, lchown, link, lstat, lutimes, mkdir, mkdtemp, open, opendir, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, statfs, symlink, truncate, unlink, utimes, watch, writeFile, } = promises;
3
3
  export default promises;
@@ -0,0 +1,120 @@
1
+ import type { Buffer } from "node:buffer";
2
+ import type { BigIntStats, Stats, CopySyncOptions, Mode, MakeDirectoryOptions, OpenDirOptions } from "node:fs";
3
+ import type { FileHandle } from "./file-handle.js";
4
+ import type { Dir, Dirent } from "./directory.js";
5
+ import type { FilePath, Position } from "./stream-utils.js";
6
+ export type ReadOptions<T extends ArrayBufferView = Buffer> = object & {
7
+ buffer?: T;
8
+ offset?: number;
9
+ length?: number;
10
+ position?: Position;
11
+ };
12
+ export type ReadResult<T extends ArrayBufferView> = {
13
+ bytesRead: number;
14
+ buffer: T;
15
+ };
16
+ export type WriteResult<T extends string | ArrayBufferView> = {
17
+ bytesWritten: number;
18
+ buffer: T;
19
+ };
20
+ export interface ReadFileOptions {
21
+ encoding?: BufferEncoding | "buffer" | null;
22
+ flag?: string | number;
23
+ signal?: AbortSignal;
24
+ }
25
+ export interface WriteFileOptions {
26
+ encoding?: BufferEncoding | null;
27
+ mode?: Mode;
28
+ flag?: string | number;
29
+ signal?: AbortSignal;
30
+ flush?: boolean;
31
+ }
32
+ export type FileData = string | ArrayBufferView;
33
+ export type FileLocation = FilePath | number;
34
+ export interface ReadFile {
35
+ (path: FileLocation, options: BufferEncoding | (ReadFileOptions & {
36
+ encoding: BufferEncoding;
37
+ })): Promise<string>;
38
+ (path: FileLocation, options?: (ReadFileOptions & {
39
+ encoding?: "buffer" | null;
40
+ }) | "buffer" | null): Promise<Buffer>;
41
+ (path: FileLocation, options?: ReadFileOptions | BufferEncoding | "buffer" | null): Promise<string | Buffer>;
42
+ }
43
+ export interface Stat {
44
+ (path: FilePath, options: {
45
+ bigint: true;
46
+ throwIfNoEntry?: true;
47
+ }): Promise<BigIntStats>;
48
+ (path: FilePath, options?: {
49
+ bigint?: false;
50
+ throwIfNoEntry?: true;
51
+ }): Promise<Stats>;
52
+ (path: FilePath, options: {
53
+ bigint?: boolean;
54
+ throwIfNoEntry: false;
55
+ }): Promise<Stats | BigIntStats | undefined>;
56
+ (path: FilePath, options?: {
57
+ bigint?: boolean;
58
+ throwIfNoEntry?: boolean;
59
+ }): Promise<Stats | BigIntStats | undefined>;
60
+ }
61
+ export interface ReadDirectory {
62
+ (path: FilePath, options: {
63
+ withFileTypes: true;
64
+ encoding?: BufferEncoding | "buffer" | null;
65
+ recursive?: boolean;
66
+ }): Promise<Dirent[]>;
67
+ (path: FilePath, options: "buffer" | {
68
+ encoding: "buffer";
69
+ withFileTypes?: false;
70
+ recursive?: boolean;
71
+ }): Promise<Buffer[]>;
72
+ (path: FilePath, options?: BufferEncoding | null | {
73
+ encoding?: BufferEncoding | null;
74
+ withFileTypes?: false;
75
+ recursive?: boolean;
76
+ }): Promise<string[]>;
77
+ (path: FilePath, options?: {
78
+ encoding?: BufferEncoding | "buffer" | null;
79
+ withFileTypes?: boolean;
80
+ recursive?: boolean;
81
+ }): Promise<string[] | Buffer[] | Dirent[]>;
82
+ }
83
+ export interface Glob {
84
+ (pattern: string | readonly string[], options: {
85
+ cwd?: string | URL;
86
+ withFileTypes: true;
87
+ exclude?: string[] | ((entry: Dirent) => boolean);
88
+ }): AsyncGenerator<Dirent>;
89
+ (pattern: string | readonly string[], options?: {
90
+ cwd?: string | URL;
91
+ withFileTypes?: false;
92
+ exclude?: string[] | ((path: string) => boolean);
93
+ }): AsyncGenerator<string>;
94
+ (pattern: string | readonly string[], options?: {
95
+ cwd?: string | URL;
96
+ withFileTypes?: boolean;
97
+ exclude?: string[] | ((path: string | Dirent) => boolean);
98
+ }): AsyncGenerator<string | Dirent>;
99
+ }
100
+ type SharedPromises = Pick<typeof import("node:fs/promises"), "access" | "chmod" | "chown" | "constants" | "copyFile" | "lchmod" | "lchown" | "link" | "lutimes" | "readlink" | "realpath" | "rename" | "rm" | "rmdir" | "statfs" | "truncate" | "unlink" | "utimes">;
101
+ export interface FsPromises extends SharedPromises {
102
+ FileHandle: typeof FileHandle;
103
+ open(path: FilePath, flags?: string | number, mode?: Mode): Promise<FileHandle>;
104
+ readFile: ReadFile;
105
+ writeFile(path: FileLocation, data: FileData, options?: BufferEncoding | WriteFileOptions): Promise<void>;
106
+ appendFile(path: FileLocation, data: FileData, options?: BufferEncoding | WriteFileOptions): Promise<void>;
107
+ cp(source: FilePath, destination: FilePath, options?: CopySyncOptions): Promise<void>;
108
+ opendir(path: FilePath, options?: OpenDirOptions): Promise<Dir>;
109
+ readdir: ReadDirectory;
110
+ stat: Stat;
111
+ lstat: Stat;
112
+ mkdtemp(prefix: FilePath, options?: BufferEncoding | "buffer" | {
113
+ encoding?: BufferEncoding | "buffer";
114
+ }): Promise<string>;
115
+ mkdir(path: FilePath, options?: number | MakeDirectoryOptions): Promise<string | undefined>;
116
+ symlink(target: FilePath, path: FilePath, type?: "dir" | "file" | "junction" | null): Promise<void>;
117
+ glob: Glob;
118
+ watch(...args: unknown[]): never;
119
+ }
120
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export { ERR_INVALID_ARG_VALUE, ERR_OUT_OF_RANGE, ERR_MISSING_ARGS, } from "../net/errors.js";
2
+ export { ERR_METHOD_NOT_IMPLEMENTED, ERR_STREAM_DESTROYED, } from "../stream/errors.js";
3
+ import { NodeError } from "../net/errors.js";
4
+ export declare class ERR_SYSTEM_ERROR extends NodeError {
5
+ constructor(message: string);
6
+ }
@@ -0,0 +1,8 @@
1
+ export { ERR_INVALID_ARG_VALUE, ERR_OUT_OF_RANGE, ERR_MISSING_ARGS, } from "../net/errors.js";
2
+ export { ERR_METHOD_NOT_IMPLEMENTED, ERR_STREAM_DESTROYED, } from "../stream/errors.js";
3
+ import { NodeError } from "../net/errors.js";
4
+ export class ERR_SYSTEM_ERROR extends NodeError {
5
+ constructor(message) {
6
+ super("ERR_SYSTEM_ERROR", message);
7
+ }
8
+ }
@@ -0,0 +1,16 @@
1
+ export { validateAbortSignal, validateBoolean, validateFunction, validateObject, validateString, validateUint32, } from "../net/validators.js";
2
+ export type FilePath = string | import("node:buffer").Buffer | URL;
3
+ export type Position = number | bigint | null;
4
+ export type WriteSyncOptions = {
5
+ offset?: number;
6
+ length?: number;
7
+ position?: Position;
8
+ };
9
+ export type ValidEncoding = BufferEncoding | "buffer" | null;
10
+ export declare function registerFileHandle(handle: object): void;
11
+ export declare function isFileHandle(handle: unknown): boolean;
12
+ export declare function normalizePath(path: unknown): URL;
13
+ export declare function toPathIfFileURL(path: URL): string;
14
+ export declare function getValidatedFd(fd: unknown): number;
15
+ export declare function parseFileMode(value: unknown, _name: string, fallback?: number): number;
16
+ export declare function validateThisInternalField(value: any, key: symbol, name: string): void;
@@ -0,0 +1,29 @@
1
+ import { pathOf } from "./writable.js";
2
+ import { fileMode } from "./mode.js";
3
+ import { validateInteger } from "../crypto/validation.js";
4
+ import { NodeTypeError } from "../net/errors.js";
5
+ export { validateAbortSignal, validateBoolean, validateFunction, validateObject, validateString, validateUint32, } from "../net/validators.js";
6
+ const handles = new WeakSet();
7
+ export function registerFileHandle(handle) {
8
+ handles.add(handle);
9
+ }
10
+ export function isFileHandle(handle) {
11
+ return typeof handle === "object" && handle !== null && handles.has(handle);
12
+ }
13
+ export function normalizePath(path) {
14
+ return new URL("file://" + pathOf(path));
15
+ }
16
+ export function toPathIfFileURL(path) {
17
+ return path.pathname;
18
+ }
19
+ export function getValidatedFd(fd) {
20
+ validateInteger(fd, "fd", 0, 2147483647);
21
+ return fd;
22
+ }
23
+ export function parseFileMode(value, _name, fallback) {
24
+ return fileMode(value, fallback);
25
+ }
26
+ export function validateThisInternalField(value, key, name) {
27
+ if (!value || !Reflect.has(value, key))
28
+ throw new NodeTypeError("ERR_INVALID_THIS", `Value of "this" must be of type ${name}`);
29
+ }