rush-fs 0.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 N-API for Rust
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,418 @@
1
+ # Hyper-FS
2
+
3
+ <p align="center">
4
+ <img src="https://img.shields.io/badge/Written%20in-Rust-orange?style=flat-square" alt="Written in Rust">
5
+ <img src="https://img.shields.io/npm/v/hyper-fs?style=flat-square" alt="NPM Version">
6
+ <img src="https://img.shields.io/npm/l/hyper-fs?style=flat-square" alt="License">
7
+ </p>
8
+
9
+ <p align="center">
10
+ A high-performance, drop-in replacement for Node.js <code>fs</code> module, powered by Rust.
11
+ </p>
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install hyper-fs
17
+ # or
18
+ pnpm add hyper-fs
19
+ ```
20
+
21
+ ## Status & Roadmap
22
+
23
+ We are rewriting `fs` APIs one by one.
24
+
25
+ > **Legend**
26
+ >
27
+ > - βœ…: Fully Supported
28
+ > - 🚧: Partially Supported / WIP
29
+ > - ✨:New feature from hyper-fs
30
+ > - ❌: Not Supported Yet
31
+
32
+ ### `readdir`
33
+
34
+ - **Node.js Arguments**:
35
+ ```ts
36
+ path: string; // βœ…
37
+ options?: {
38
+ encoding?: string; // 🚧 ('utf8' default; 'buffer' not supported)
39
+ withFileTypes?: boolean; // βœ…
40
+ recursive?: boolean; // βœ…
41
+ concurrency?: number; // ✨
42
+ };
43
+ ```
44
+ - **Return Type**:
45
+ ```ts
46
+ string[]
47
+ | {
48
+ name: string, // βœ…
49
+ parentPath: string, // βœ…
50
+ isDir: boolean // βœ…
51
+ }[]
52
+ ```
53
+
54
+ ### `readFile`
55
+
56
+ - **Node.js Arguments**:
57
+ ```ts
58
+ path: string; // βœ…
59
+ options?: {
60
+ encoding?: string; // βœ… (utf8, ascii, latin1, base64, base64url, hex)
61
+ flag?: string; // βœ… (r, r+, w+, a+, etc.)
62
+ };
63
+ ```
64
+ - **Return Type**: `string | Buffer`
65
+
66
+ ### `writeFile`
67
+
68
+ - **Node.js Arguments**:
69
+ ```ts
70
+ path: string; // βœ…
71
+ data: string | Buffer; // βœ…
72
+ options?: {
73
+ encoding?: string; // βœ… (utf8, ascii, latin1, base64, base64url, hex)
74
+ mode?: number; // βœ…
75
+ flag?: string; // βœ… (w, wx, a, ax)
76
+ };
77
+ ```
78
+
79
+ ### `appendFile`
80
+
81
+ - **Node.js Arguments**:
82
+ ```ts
83
+ path: string; // βœ…
84
+ data: string | Buffer; // βœ…
85
+ options?: {
86
+ encoding?: string; // βœ… (utf8, ascii, latin1, base64, base64url, hex)
87
+ mode?: number; // βœ…
88
+ flag?: string; // βœ…
89
+ };
90
+ ```
91
+
92
+ ### `copyFile`
93
+
94
+ - **Node.js Arguments**:
95
+ ```ts
96
+ src: string; // βœ…
97
+ dest: string; // βœ…
98
+ mode?: number; // βœ… (COPYFILE_EXCL)
99
+ ```
100
+
101
+ ### `cp`
102
+
103
+ - **Node.js Arguments** (Node 16.7+):
104
+ ```ts
105
+ src: string; // βœ…
106
+ dest: string; // βœ…
107
+ options?: {
108
+ recursive?: boolean; // βœ…
109
+ force?: boolean; // βœ… (default: true)
110
+ errorOnExist?: boolean; // βœ…
111
+ preserveTimestamps?: boolean; // βœ…
112
+ dereference?: boolean; // βœ…
113
+ verbatimSymlinks?: boolean; // βœ…
114
+ concurrency?: number; // ✨
115
+ };
116
+ ```
117
+
118
+ ### `mkdir`
119
+
120
+ - **Node.js Arguments**:
121
+ ```ts
122
+ path: string; // βœ…
123
+ options?: {
124
+ recursive?: boolean; // βœ…
125
+ mode?: number; // βœ…
126
+ };
127
+ ```
128
+ - **Return Type**: `string | undefined` (first created path when recursive)
129
+
130
+ ### `rm`
131
+
132
+ - **Node.js Arguments**:
133
+ ```ts
134
+ path: string; // βœ…
135
+ options?: {
136
+ force?: boolean; // βœ…
137
+ maxRetries?: number; // βœ…
138
+ recursive?: boolean; // βœ…
139
+ retryDelay?: number; // βœ… (default: 100ms)
140
+ concurrency?: number; // ✨
141
+ };
142
+ ```
143
+
144
+ ### `rmdir`
145
+
146
+ - **Node.js Arguments**:
147
+ ```ts
148
+ path: string // βœ…
149
+ ```
150
+
151
+ ### `stat`
152
+
153
+ - **Node.js Arguments**:
154
+ ```ts
155
+ path: string // βœ…
156
+ ```
157
+ - **Return Type**: `Stats`
158
+ - Numeric fields: `dev`, `mode`, `nlink`, `uid`, `gid`, `rdev`, `blksize`, `ino`, `size`, `blocks`, `atimeMs`, `mtimeMs`, `ctimeMs`, `birthtimeMs`
159
+ - **Date fields**: `atime`, `mtime`, `ctime`, `birthtime` β†’ `Date` objects βœ…
160
+ - Methods: `isFile()`, `isDirectory()`, `isSymbolicLink()`, ...
161
+ - **Error distinction**: `ENOENT` vs `EACCES` βœ…
162
+
163
+ ### `lstat`
164
+
165
+ - **Node.js Arguments**:
166
+ ```ts
167
+ path: string // βœ…
168
+ ```
169
+ - **Return Type**: `Stats`
170
+
171
+ ### `fstat`
172
+
173
+ - **Status**: ❌
174
+
175
+ ### `access`
176
+
177
+ - **Node.js Arguments**:
178
+ ```ts
179
+ path: string; // βœ…
180
+ mode?: number; // βœ… (F_OK, R_OK, W_OK, X_OK)
181
+ ```
182
+
183
+ ### `exists`
184
+
185
+ - **Node.js Arguments**:
186
+ ```ts
187
+ path: string // βœ…
188
+ ```
189
+ - **Return Type**: `boolean`
190
+
191
+ ### `open`
192
+
193
+ - **Status**: ❌
194
+
195
+ ### `opendir`
196
+
197
+ - **Status**: ❌
198
+
199
+ ### `close`
200
+
201
+ - **Status**: ❌
202
+
203
+ ### `unlink`
204
+
205
+ - **Node.js Arguments**:
206
+ ```ts
207
+ path: string // βœ…
208
+ ```
209
+
210
+ ### `rename`
211
+
212
+ - **Node.js Arguments**:
213
+ ```ts
214
+ oldPath: string // βœ…
215
+ newPath: string // βœ…
216
+ ```
217
+
218
+ ### `readlink`
219
+
220
+ - **Node.js Arguments**:
221
+ ```ts
222
+ path: string // βœ…
223
+ ```
224
+ - **Return Type**: `string`
225
+
226
+ ### `realpath`
227
+
228
+ - **Node.js Arguments**:
229
+ ```ts
230
+ path: string // βœ…
231
+ ```
232
+ - **Return Type**: `string`
233
+
234
+ ### `chmod`
235
+
236
+ - **Node.js Arguments**:
237
+ ```ts
238
+ path: string // βœ…
239
+ mode: number // βœ…
240
+ ```
241
+
242
+ ### `chown`
243
+
244
+ - **Node.js Arguments**:
245
+ ```ts
246
+ path: string // βœ…
247
+ uid: number // βœ…
248
+ gid: number // βœ…
249
+ ```
250
+
251
+ ### `utimes`
252
+
253
+ - **Node.js Arguments**:
254
+ ```ts
255
+ path: string // βœ…
256
+ atime: number // βœ…
257
+ mtime: number // βœ…
258
+ ```
259
+
260
+ ### `truncate`
261
+
262
+ - **Node.js Arguments**:
263
+ ```ts
264
+ path: string; // βœ…
265
+ len?: number; // βœ…
266
+ ```
267
+
268
+ ### `glob`
269
+
270
+ - **Node.js Arguments**:
271
+ ```ts
272
+ pattern: string; // βœ…
273
+ options?: {
274
+ cwd?: string; // βœ…
275
+ withFileTypes?: boolean; // βœ…
276
+ exclude?: string[]; // βœ…
277
+ concurrency?: number; // ✨
278
+ gitIgnore?: boolean; // ✨
279
+ };
280
+ ```
281
+
282
+ ### `symlink`
283
+
284
+ - **Node.js Arguments**:
285
+ ```ts
286
+ target: string // βœ…
287
+ path: string // βœ…
288
+ type?: 'file' | 'dir' | 'junction' // βœ… (Windows only, ignored on Unix)
289
+ ```
290
+
291
+ ### `link`
292
+
293
+ - **Node.js Arguments**:
294
+ ```ts
295
+ existingPath: string // βœ…
296
+ newPath: string // βœ…
297
+ ```
298
+
299
+ ### `mkdtemp`
300
+
301
+ - **Node.js Arguments**:
302
+ ```ts
303
+ prefix: string // βœ…
304
+ ```
305
+ - **Return Type**: `string`
306
+ - Uses OS-level random source (`/dev/urandom` on Unix, `BCryptGenRandom` on Windows) with up to 10 retries βœ…
307
+
308
+ ### `watch`
309
+
310
+ - **Status**: ❌
311
+
312
+ ## Usage
313
+
314
+ ```ts
315
+ import { readdir, stat, readFile, writeFile, mkdir, rm } from 'hyper-fs'
316
+
317
+ // Read directory
318
+ const files = await readdir('./src')
319
+
320
+ // Recursive with file types
321
+ const entries = await readdir('./src', {
322
+ recursive: true,
323
+ withFileTypes: true,
324
+ })
325
+
326
+ // Read / write files
327
+ const content = await readFile('./package.json', { encoding: 'utf8' })
328
+ await writeFile('./output.txt', 'hello world')
329
+
330
+ // File stats
331
+ const s = await stat('./package.json')
332
+ console.log(s.size, s.isFile())
333
+
334
+ // Create directory
335
+ await mkdir('./new-dir', { recursive: true })
336
+
337
+ // Remove
338
+ await rm('./temp', { recursive: true, force: true })
339
+ ```
340
+
341
+ ## Benchmarks
342
+
343
+ > Tested on Apple Silicon (arm64), Node.js 24.0.2, release build with LTO.
344
+ > Run `pnpm build && pnpm bench` to reproduce.
345
+
346
+ ### Where Hyper-FS Shines
347
+
348
+ These are the scenarios where Rust's parallelism and zero-copy I/O make a real difference:
349
+
350
+ | Scenario | Node.js | Hyper-FS | Speedup |
351
+ | ------------------------------------------------ | --------- | -------- | --------- |
352
+ | `readdir` recursive (node_modules, ~30k entries) | 281 ms | 23 ms | **12x** |
353
+ | `glob` recursive (`**/*.rs`) | 25 ms | 1.46 ms | **17x** |
354
+ | `glob` recursive vs fast-glob | 102 ms | 1.46 ms | **70x** |
355
+ | `copyFile` 4 MB | 4.67 ms | 0.09 ms | **50x** |
356
+ | `readFile` 4 MB utf8 | 1.86 ms | 0.92 ms | **2x** |
357
+ | `readFile` 64 KB utf8 | 42 Β΅s | 18 Β΅s | **2.4x** |
358
+ | `rm` 2000 files (4 threads) | 92 ms | 53 ms | **1.75x** |
359
+ | `access` R_OK (directory) | 4.18 Β΅s | 1.55 Β΅s | **2.7x** |
360
+ | `cp` 500-file flat dir (4 threads) | 86.45 ms | 32.88 ms | **2.6x** |
361
+ | `cp` tree dir ~363 nodes (4 threads) | 108.73 ms | 46.88 ms | **2.3x** |
362
+
363
+ ### On Par with Node.js
364
+
365
+ Single-file operations have a ~0.3 Β΅s napi bridge overhead, making them roughly equivalent:
366
+
367
+ | Scenario | Node.js | Hyper-FS | Ratio |
368
+ | -------------------------- | ------- | -------- | ----- |
369
+ | `stat` (single file) | 1.45 Β΅s | 1.77 Β΅s | 1.2x |
370
+ | `readFile` small (Buffer) | 8.86 Β΅s | 9.46 Β΅s | 1.1x |
371
+ | `writeFile` small (string) | 74 Β΅s | 66 Β΅s | 0.9x |
372
+ | `writeFile` small (Buffer) | 115 Β΅s | 103 Β΅s | 0.9x |
373
+ | `appendFile` | 30 Β΅s | 27 Β΅s | 0.9x |
374
+
375
+ ### Where Node.js Wins
376
+
377
+ Lightweight built-in calls where napi overhead is proportionally large:
378
+
379
+ | Scenario | Node.js | Hyper-FS | Note |
380
+ | ---------------------------- | ------- | -------- | --------------------------------- |
381
+ | `existsSync` (existing file) | 444 ns | 1.34 Β΅s | Node.js internal fast path |
382
+ | `accessSync` F_OK | 456 ns | 1.46 Β΅s | Same β€” napi overhead dominates |
383
+ | `writeFile` 4 MB string | 2.93 ms | 5.69 ms | Large string crossing napi bridge |
384
+
385
+ ### Parallelism
386
+
387
+ Hyper-FS uses multi-threaded parallelism for operations that traverse the filesystem:
388
+
389
+ | API | Library | `concurrency` option | Default |
390
+ | --------------------- | ------------------------------------------------------------------------- | -------------------- | ------- |
391
+ | `readdir` (recursive) | [jwalk](https://github.com/Byron/jwalk) | βœ… | auto |
392
+ | `glob` | [ignore](https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore) | βœ… | 4 |
393
+ | `rm` (recursive) | [rayon](https://github.com/rayon-rs/rayon) | βœ… | 1 |
394
+ | `cp` (recursive) | [rayon](https://github.com/rayon-rs/rayon) | βœ… | 1 |
395
+
396
+ Single-file operations (`stat`, `readFile`, `writeFile`, `chmod`, etc.) are atomic syscalls β€” parallelism does not apply.
397
+
398
+ ### Key Takeaway
399
+
400
+ **Hyper-FS excels at recursive / batch filesystem operations** (readdir, glob, rm, cp) where Rust's parallel walkers deliver 2–70x speedups. For single-file operations it performs on par with Node.js. The napi bridge adds a fixed ~0.3 Β΅s overhead per call, which only matters for sub-microsecond operations like `existsSync`.
401
+
402
+ **`cp` benchmark detail** (Apple Silicon, release build):
403
+
404
+ | Scenario | Node.js | Hyper-FS 1T | Hyper-FS 4T | Hyper-FS 8T |
405
+ | ----------------------------------------- | --------- | ----------- | ----------- | ----------- |
406
+ | Flat dir (500 files) | 86.45 ms | 61.56 ms | 32.88 ms | 36.67 ms |
407
+ | Tree dir (breadth=4, depth=3, ~84 nodes) | 23.80 ms | 16.94 ms | 10.62 ms | 9.76 ms |
408
+ | Tree dir (breadth=3, depth=5, ~363 nodes) | 108.73 ms | 75.39 ms | 46.88 ms | 46.18 ms |
409
+
410
+ Optimal concurrency for `cp` is **4 threads** on Apple Silicon β€” beyond that, I/O bandwidth becomes the bottleneck and diminishing returns set in.
411
+
412
+ ## Contributing
413
+
414
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for the complete development guide β€” from environment setup, referencing Node.js source, writing Rust implementations, to testing and benchmarking.
415
+
416
+ ## License
417
+
418
+ MIT