@zenfs/core 1.1.4 → 1.1.5
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/dist/backends/fetch.js +5 -5
- package/dist/config.js +1 -0
- package/license.md +1 -1
- package/package.json +5 -3
- package/readme.md +3 -8
- package/scripts/make-index.js +3 -3
- package/scripts/test.js +31 -0
- package/tests/assignment.ts +20 -0
- package/tests/common.ts +21 -0
- package/tests/data/49chars.txt +1 -0
- package/tests/data/a.js +46 -0
- package/tests/data/a1.js +46 -0
- package/tests/data/elipses.txt +1 -0
- package/tests/data/empty.txt +0 -0
- package/tests/data/exit.js +22 -0
- package/tests/data/x.txt +1 -0
- package/tests/devices.test.ts +29 -0
- package/tests/fs/appendFile.test.ts +33 -0
- package/tests/fs/chmod.test.ts +48 -0
- package/tests/fs/dir.test.ts +156 -0
- package/tests/fs/directory.test.ts +129 -0
- package/tests/fs/errors.test.ts +53 -0
- package/tests/fs/exists.test.ts +22 -0
- package/tests/fs/links.test.ts +46 -0
- package/tests/fs/open.test.ts +39 -0
- package/tests/fs/permissions.test.ts +52 -0
- package/tests/fs/read.test.ts +67 -0
- package/tests/fs/readFile.test.ts +73 -0
- package/tests/fs/readdir.test.ts +87 -0
- package/tests/fs/rename.test.ts +107 -0
- package/tests/fs/stat.test.ts +48 -0
- package/tests/fs/streams.test.ts +177 -0
- package/tests/fs/times.test.ts +84 -0
- package/tests/fs/truncate.test.ts +94 -0
- package/tests/fs/watch.test.ts +124 -0
- package/tests/fs/write.test.ts +58 -0
- package/tests/fs/writeFile.test.ts +69 -0
- package/tests/handle.test.ts +60 -0
- package/tests/mutex.test.ts +62 -0
- package/tests/path.test.ts +34 -0
- package/tests/port/channel.test.ts +39 -0
- package/tests/port/config.test.ts +31 -0
- package/tests/port/config.worker.ts +5 -0
- package/tests/port/remote.test.ts +33 -0
- package/tests/port/remote.worker.ts +5 -0
- package/tests/port/timeout.test.ts +48 -0
- package/tests/readme.md +5 -0
- package/tests/setup/common.ts +28 -0
- package/tests/setup/cow+fetch.ts +43 -0
- package/tests/setup/memory.ts +3 -0
- package/tests/tsconfig.json +14 -0
- package/src/backends/backend.ts +0 -160
- package/src/backends/fetch.ts +0 -179
- package/src/backends/file_index.ts +0 -210
- package/src/backends/memory.ts +0 -50
- package/src/backends/overlay.ts +0 -568
- package/src/backends/port/fs.ts +0 -335
- package/src/backends/port/readme.md +0 -54
- package/src/backends/port/rpc.ts +0 -167
- package/src/backends/readme.md +0 -3
- package/src/backends/store/fs.ts +0 -715
- package/src/backends/store/readme.md +0 -9
- package/src/backends/store/simple.ts +0 -146
- package/src/backends/store/store.ts +0 -173
- package/src/config.ts +0 -152
- package/src/credentials.ts +0 -31
- package/src/devices.ts +0 -471
- package/src/emulation/async.ts +0 -834
- package/src/emulation/constants.ts +0 -182
- package/src/emulation/dir.ts +0 -138
- package/src/emulation/index.ts +0 -8
- package/src/emulation/path.ts +0 -440
- package/src/emulation/promises.ts +0 -1098
- package/src/emulation/shared.ts +0 -135
- package/src/emulation/streams.ts +0 -34
- package/src/emulation/sync.ts +0 -845
- package/src/emulation/watchers.ts +0 -193
- package/src/error.ts +0 -307
- package/src/file.ts +0 -661
- package/src/filesystem.ts +0 -174
- package/src/index.ts +0 -25
- package/src/inode.ts +0 -132
- package/src/mixins/async.ts +0 -208
- package/src/mixins/index.ts +0 -5
- package/src/mixins/mutexed.ts +0 -257
- package/src/mixins/readonly.ts +0 -96
- package/src/mixins/shared.ts +0 -25
- package/src/mixins/sync.ts +0 -58
- package/src/polyfills.ts +0 -21
- package/src/stats.ts +0 -363
- package/src/utils.ts +0 -288
package/dist/backends/fetch.js
CHANGED
|
@@ -2,21 +2,21 @@ import { Errno, ErrnoError } from '../error.js';
|
|
|
2
2
|
import { IndexFS } from './file_index.js';
|
|
3
3
|
async function fetchFile(path, type) {
|
|
4
4
|
const response = await fetch(path).catch((e) => {
|
|
5
|
-
throw new ErrnoError(Errno.EIO, e.message);
|
|
5
|
+
throw new ErrnoError(Errno.EIO, e.message, path);
|
|
6
6
|
});
|
|
7
7
|
if (!response.ok) {
|
|
8
|
-
throw new ErrnoError(Errno.EIO, 'fetch failed: response returned code ' + response.status);
|
|
8
|
+
throw new ErrnoError(Errno.EIO, 'fetch failed: response returned code ' + response.status, path);
|
|
9
9
|
}
|
|
10
10
|
switch (type) {
|
|
11
11
|
case 'buffer': {
|
|
12
12
|
const arrayBuffer = await response.arrayBuffer().catch((e) => {
|
|
13
|
-
throw new ErrnoError(Errno.EIO, e.message);
|
|
13
|
+
throw new ErrnoError(Errno.EIO, e.message, path);
|
|
14
14
|
});
|
|
15
15
|
return new Uint8Array(arrayBuffer);
|
|
16
16
|
}
|
|
17
17
|
case 'json':
|
|
18
18
|
return response.json().catch((e) => {
|
|
19
|
-
throw new ErrnoError(Errno.EIO, e.message);
|
|
19
|
+
throw new ErrnoError(Errno.EIO, e.message, path);
|
|
20
20
|
});
|
|
21
21
|
default:
|
|
22
22
|
throw new ErrnoError(Errno.EINVAL, 'Invalid download type: ' + type);
|
|
@@ -58,11 +58,11 @@ export class FetchFS extends IndexFS {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
constructor({ index = 'index.json', baseUrl = '' }) {
|
|
61
|
-
super(typeof index != 'string' ? index : fetchFile(index, 'json'));
|
|
62
61
|
// prefix url must end in a directory separator.
|
|
63
62
|
if (baseUrl.at(-1) != '/') {
|
|
64
63
|
baseUrl += '/';
|
|
65
64
|
}
|
|
65
|
+
super(typeof index != 'string' ? index : fetchFile(baseUrl + index, 'json'));
|
|
66
66
|
this.baseUrl = baseUrl;
|
|
67
67
|
}
|
|
68
68
|
metadata() {
|
package/dist/config.js
CHANGED
|
@@ -19,6 +19,7 @@ export async function resolveMountConfig(configuration, _depth = 0) {
|
|
|
19
19
|
throw new ErrnoError(Errno.EINVAL, 'Invalid mount configuration');
|
|
20
20
|
}
|
|
21
21
|
if (configuration instanceof FileSystem) {
|
|
22
|
+
await configuration.ready();
|
|
22
23
|
return configuration;
|
|
23
24
|
}
|
|
24
25
|
if (isBackend(configuration)) {
|
package/license.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Copyright (c) James Prevett and other ZenFS contributors.
|
|
2
2
|
Copyright (c) 2013-2023 John Vilk and other BrowserFS contributors.
|
|
3
|
-
Copyright (c) Joyent, Inc. and other Node contributors for `test/
|
|
3
|
+
Copyright (c) Joyent, Inc. and other Node contributors for `test/data`.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "A filesystem, anywhere",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
"storage"
|
|
15
15
|
],
|
|
16
16
|
"bin": {
|
|
17
|
-
"make-index": "scripts/make-index.js"
|
|
17
|
+
"make-index": "scripts/make-index.js",
|
|
18
|
+
"zenfs-test": "scripts/test.js"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
21
|
"dist",
|
|
21
|
-
"
|
|
22
|
+
"tests",
|
|
22
23
|
"license.md",
|
|
23
24
|
"tsconfig.json",
|
|
24
25
|
"eslint.shared.js"
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"format": "prettier --write .",
|
|
53
54
|
"format:check": "prettier --check .",
|
|
54
55
|
"lint": "eslint src tests",
|
|
56
|
+
"test:common": "tsx --test --experimental-test-coverage 'tests/**/!(fs)/*.test.ts' 'tests/*.test.ts'",
|
|
55
57
|
"test": "tsx --test --experimental-test-coverage",
|
|
56
58
|
"build": "tsc -p tsconfig.json",
|
|
57
59
|
"build:docs": "typedoc",
|
package/readme.md
CHANGED
|
@@ -29,15 +29,10 @@ npm install @zenfs/core
|
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
|
-
> [!NOTE]
|
|
33
|
-
> The examples are written in ESM.
|
|
34
|
-
> If you are using CJS, you can `require` the package.
|
|
35
|
-
> If using a browser environment, you can use a `<script>` with `type=module` (you may need to use import maps)
|
|
36
|
-
|
|
37
32
|
```js
|
|
38
|
-
import fs from '@zenfs/core'; // You can also use the
|
|
33
|
+
import { fs } from '@zenfs/core'; // You can also use the default export
|
|
39
34
|
|
|
40
|
-
fs.writeFileSync('/test.txt', '
|
|
35
|
+
fs.writeFileSync('/test.txt', 'You can do this in anywhere (including browsers)!');
|
|
41
36
|
|
|
42
37
|
const contents = fs.readFileSync('/test.txt', 'utf-8');
|
|
43
38
|
console.log(contents);
|
|
@@ -148,7 +143,7 @@ fs.umount('/mnt/zip'); // finished using the zip
|
|
|
148
143
|
> [!CAUTION]
|
|
149
144
|
> Instances of backends follow the _internal_ API. You should never use a backend's methods unless you are extending a backend.
|
|
150
145
|
|
|
151
|
-
|
|
146
|
+
### Devices and device files
|
|
152
147
|
|
|
153
148
|
> [!WARNING]
|
|
154
149
|
> This is an **experimental** feature. Breaking changes may occur during non-major releases. Using this feature is the fastest way to make it stable.
|
package/scripts/make-index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readdirSync, statSync, writeFileSync } from 'fs';
|
|
2
|
+
import { readdirSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { minimatch } from 'minimatch';
|
|
4
|
-
import { join, relative, resolve } from 'path/posix';
|
|
5
|
-
import { parseArgs } from 'util';
|
|
4
|
+
import { join, relative, resolve } from 'node:path/posix';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
6
|
|
|
7
7
|
const { values: options, positionals } = parseArgs({
|
|
8
8
|
options: {
|
package/scripts/test.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from 'node:child_process';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
|
+
|
|
7
|
+
const { values: options, positionals } = parseArgs({
|
|
8
|
+
options: {
|
|
9
|
+
help: { short: 'h', type: 'boolean', default: false },
|
|
10
|
+
verbose: { type: 'boolean', default: false },
|
|
11
|
+
},
|
|
12
|
+
allowPositionals: true,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (options.help) {
|
|
16
|
+
console.log(`zenfs-test [...options] <...paths>
|
|
17
|
+
|
|
18
|
+
paths: The setup files to run tests on
|
|
19
|
+
|
|
20
|
+
options:
|
|
21
|
+
--help, -h Outputs this help message
|
|
22
|
+
--verbose Output verbose messages
|
|
23
|
+
`);
|
|
24
|
+
process.exit();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const setupFile of positionals) {
|
|
28
|
+
if (options.verbose) console.debug('Running tests for:', setupFile);
|
|
29
|
+
process.env.SETUP = setupFile;
|
|
30
|
+
execSync('tsx --test --experimental-test-coverage ' + join(import.meta.dirname, '../tests/fs/*.test.ts'), { stdio: 'inherit' });
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This test assigns the exported fs module from ZenFS with the one exported from Node.
|
|
5
|
+
This ensures anything new that is added will be caught
|
|
6
|
+
|
|
7
|
+
Notes on omissions and exclusions:
|
|
8
|
+
- __promisify__ is omitted as it is metadata
|
|
9
|
+
- native is omitted as zenfs isn't native
|
|
10
|
+
- ReadStream and WriteStream are excluded since they are polfilled from another module
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { fs as zen } from '../src/index.js';
|
|
14
|
+
import type * as node from 'node:fs';
|
|
15
|
+
|
|
16
|
+
type Mock = {
|
|
17
|
+
[K in Exclude<keyof typeof node, 'ReadStream' | 'WriteStream'>]: Omit<(typeof node)[K], '__promisify__' | 'native'>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const _module: Mock = zen;
|
package/tests/common.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { join, resolve } from 'node:path';
|
|
2
|
+
import { Worker } from 'node:worker_threads';
|
|
3
|
+
import { fs } from '../src/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Typescript Worker
|
|
7
|
+
* @see https://github.com/privatenumber/tsx/issues/354
|
|
8
|
+
* @see https://github.com/nodejs/node/issues/47747#issuecomment-2287745567
|
|
9
|
+
*/
|
|
10
|
+
export function createTSWorker(source: string): Worker {
|
|
11
|
+
return new Worker(`import('tsx/esm/api').then(tsx => {tsx.register();import('${source}');});`, { eval: true });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const setupPath = resolve(process.env.SETUP || join(import.meta.dirname, 'setup/memory.ts'));
|
|
15
|
+
|
|
16
|
+
await import(setupPath).catch(error => {
|
|
17
|
+
console.log('Failed to import test setup:');
|
|
18
|
+
throw error;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export { fs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0123456789abcdef0123456789abcdef0123456789abcdef
|
package/tests/data/a.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
var c = require('./b/c');
|
|
23
|
+
|
|
24
|
+
console.error('load fixtures/a.js');
|
|
25
|
+
|
|
26
|
+
var string = 'A';
|
|
27
|
+
|
|
28
|
+
exports.SomeClass = c.SomeClass;
|
|
29
|
+
|
|
30
|
+
exports.A = function () {
|
|
31
|
+
return string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.C = function () {
|
|
35
|
+
return c.C();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.D = function () {
|
|
39
|
+
return c.D();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.number = 42;
|
|
43
|
+
|
|
44
|
+
process.on('exit', function () {
|
|
45
|
+
string = 'A done';
|
|
46
|
+
});
|
package/tests/data/a1.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
var c = require('./b/c');
|
|
23
|
+
|
|
24
|
+
console.error('load fixtures/a.js');
|
|
25
|
+
|
|
26
|
+
var string = 'A';
|
|
27
|
+
|
|
28
|
+
exports.SomeClass = c.SomeClass;
|
|
29
|
+
|
|
30
|
+
exports.A = function () {
|
|
31
|
+
return string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.C = function () {
|
|
35
|
+
return c.C();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.D = function () {
|
|
39
|
+
return c.D();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.number = 42;
|
|
43
|
+
|
|
44
|
+
process.on('exit', function () {
|
|
45
|
+
string = 'A done';
|
|
46
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
process.exit(process.argv[2] || 1);
|
package/tests/data/x.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xyz
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { suite, test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { configure } from '../src/config.js';
|
|
4
|
+
import * as fs from '../src/emulation/index.js';
|
|
5
|
+
import { S_IFCHR, S_IFMT } from '../src/emulation/constants.js';
|
|
6
|
+
|
|
7
|
+
await configure({
|
|
8
|
+
addDevices: true,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
suite('Devices', () => {
|
|
12
|
+
test('Correct file type', () => {
|
|
13
|
+
assert.equal(fs.statSync('/dev/null').mode & S_IFMT, S_IFCHR);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('Read from /dev/zero', () => {
|
|
17
|
+
const data = new Uint8Array(100).fill(1);
|
|
18
|
+
|
|
19
|
+
const fd = fs.openSync('/dev/zero', 'r');
|
|
20
|
+
fs.readSync(fd, data);
|
|
21
|
+
fs.closeSync(fd);
|
|
22
|
+
|
|
23
|
+
assert(data.every(v => v === 0));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Write to /dev/full (throws)', () => {
|
|
27
|
+
assert.throws(() => fs.writeFileSync('/dev/full', '...'), { code: 'ENOSPC' });
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { suite, test } from 'node:test';
|
|
3
|
+
import { fs } from '../common.js';
|
|
4
|
+
|
|
5
|
+
const content = 'Sample content',
|
|
6
|
+
original = 'ABCD';
|
|
7
|
+
|
|
8
|
+
suite('appendFile', () => {
|
|
9
|
+
test('create an empty file and add content', async () => {
|
|
10
|
+
const filename = 'append.txt';
|
|
11
|
+
await fs.promises.appendFile(filename, content);
|
|
12
|
+
const data = await fs.promises.readFile(filename, 'utf8');
|
|
13
|
+
assert(data == content);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('append data to a non-empty file', async () => {
|
|
17
|
+
const filename = 'append2.txt';
|
|
18
|
+
|
|
19
|
+
await fs.promises.writeFile(filename, original);
|
|
20
|
+
await fs.promises.appendFile(filename, content);
|
|
21
|
+
const data = await fs.promises.readFile(filename, 'utf8');
|
|
22
|
+
assert(data == original + content);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('append a buffer to the file', async () => {
|
|
26
|
+
const filename = 'append3.txt';
|
|
27
|
+
|
|
28
|
+
await fs.promises.writeFile(filename, original);
|
|
29
|
+
await fs.promises.appendFile(filename, content);
|
|
30
|
+
const data = await fs.promises.readFile(filename, 'utf8');
|
|
31
|
+
assert(data == original + content);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { suite, test } from 'node:test';
|
|
3
|
+
import { fs } from '../common.js';
|
|
4
|
+
|
|
5
|
+
const asyncMode = 0o777;
|
|
6
|
+
const syncMode = 0o644;
|
|
7
|
+
|
|
8
|
+
suite('chmod tests', () => {
|
|
9
|
+
test('chmod', async () => {
|
|
10
|
+
const file1 = 'a.js';
|
|
11
|
+
|
|
12
|
+
await fs.promises.chmod(file1, asyncMode.toString(8));
|
|
13
|
+
|
|
14
|
+
const stats = await fs.promises.stat(file1);
|
|
15
|
+
assert((stats.mode & 0o777) === asyncMode);
|
|
16
|
+
|
|
17
|
+
fs.chmodSync(file1, syncMode);
|
|
18
|
+
assert((fs.statSync(file1).mode & 0o777) === syncMode);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('fchmod', async () => {
|
|
22
|
+
const file2 = 'a1.js';
|
|
23
|
+
|
|
24
|
+
const handle = await fs.promises.open(file2, 'a', 0o644);
|
|
25
|
+
|
|
26
|
+
await handle.chmod(asyncMode);
|
|
27
|
+
const stats = await handle.stat();
|
|
28
|
+
|
|
29
|
+
assert((stats.mode & 0o777) === asyncMode);
|
|
30
|
+
|
|
31
|
+
fs.fchmodSync(handle.fd, syncMode);
|
|
32
|
+
assert((fs.statSync(file2).mode & 0o777) === syncMode);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('lchmod', async () => {
|
|
36
|
+
const link = 'symbolic-link';
|
|
37
|
+
const target = 'a1.js';
|
|
38
|
+
|
|
39
|
+
await fs.promises.symlink(target, link);
|
|
40
|
+
await fs.promises.lchmod(link, asyncMode);
|
|
41
|
+
|
|
42
|
+
const stats = await fs.promises.lstat(link);
|
|
43
|
+
assert((stats.mode & 0o777) === asyncMode);
|
|
44
|
+
|
|
45
|
+
fs.lchmodSync(link, syncMode);
|
|
46
|
+
assert((fs.lstatSync(link).mode & 0o777) === syncMode);
|
|
47
|
+
});
|
|
48
|
+
});
|