@zenfs/core 0.0.8 → 0.0.9
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/ApiError.d.ts +2 -2
- package/dist/ApiError.js +11 -7
- package/dist/backends/AsyncStore.d.ts +4 -5
- package/dist/backends/AsyncStore.js +12 -12
- package/dist/backends/InMemory.d.ts +2 -3
- package/dist/backends/SyncStore.d.ts +8 -9
- package/dist/backends/SyncStore.js +12 -12
- package/dist/browser.min.js +6 -19
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/callbacks.d.ts +6 -6
- package/dist/emulation/callbacks.js +3 -2
- package/dist/emulation/promises.d.ts +6 -6
- package/dist/emulation/promises.js +2 -1
- package/dist/emulation/sync.d.ts +6 -6
- package/dist/emulation/sync.js +2 -1
- package/dist/file.d.ts +23 -24
- package/dist/file.js +18 -20
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +9 -9
- package/dist/inode.d.ts +2 -3
- package/dist/inode.js +17 -17
- package/dist/stats.d.ts +3 -4
- package/dist/stats.js +13 -13
- package/dist/utils.d.ts +10 -5
- package/dist/utils.js +2 -8
- package/package.json +1 -3
package/dist/inode.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Stats, FileType } from './stats.js';
|
|
2
|
-
import {
|
|
2
|
+
import { decode, encode } from './utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generic inode definition that can easily be serialized.
|
|
5
5
|
*/
|
|
@@ -7,11 +7,9 @@ export default class Inode {
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts the buffer into an Inode.
|
|
9
9
|
*/
|
|
10
|
-
static
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
return new Inode(buffer.toString('ascii', 38), buffer.readUInt32LE(0), buffer.readUInt16LE(4), buffer.readDoubleLE(6), buffer.readDoubleLE(14), buffer.readDoubleLE(22), buffer.readUInt32LE(30), buffer.readUInt32LE(34));
|
|
10
|
+
static Deserialize(data) {
|
|
11
|
+
const view = new DataView('buffer' in data ? data.buffer : data);
|
|
12
|
+
return new Inode(decode(view.buffer.slice(38)), view.getUint32(0, true), view.getUint16(4, true), view.getFloat64(6, true), view.getFloat64(14, true), view.getFloat64(22, true), view.getUint32(30, true), view.getUint32(34, true));
|
|
15
13
|
}
|
|
16
14
|
constructor(id, size, mode, atime, mtime, ctime, uid, gid) {
|
|
17
15
|
this.id = id;
|
|
@@ -33,22 +31,24 @@ export default class Inode {
|
|
|
33
31
|
* Get the size of this Inode, in bytes.
|
|
34
32
|
*/
|
|
35
33
|
getSize() {
|
|
36
|
-
// ASSUMPTION: ID is
|
|
34
|
+
// ASSUMPTION: ID is 1 byte per char.
|
|
37
35
|
return 38 + this.id.length;
|
|
38
36
|
}
|
|
39
37
|
/**
|
|
40
38
|
* Writes the inode into the start of the buffer.
|
|
41
39
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
serialize(data = new Uint8Array(this.getSize())) {
|
|
41
|
+
const view = new DataView('buffer' in data ? data.buffer : data);
|
|
42
|
+
view.setUint32(0, this.size, true);
|
|
43
|
+
view.setUint16(4, this.mode, true);
|
|
44
|
+
view.setFloat64(6, this.atime, true);
|
|
45
|
+
view.setFloat64(14, this.mtime, true);
|
|
46
|
+
view.setFloat64(22, this.ctime, true);
|
|
47
|
+
view.setUint32(30, this.uid, true);
|
|
48
|
+
view.setUint32(34, this.gid, true);
|
|
49
|
+
const buffer = new Uint8Array(view.buffer);
|
|
50
|
+
buffer.set(encode(this.id), 38);
|
|
51
|
+
return buffer;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Updates the Inode using information from the stats object. Used by file
|
package/dist/stats.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
2
|
import type { StatsBase } from 'fs';
|
|
4
3
|
import { Cred } from './cred.js';
|
|
5
4
|
/**
|
|
@@ -18,7 +17,7 @@ export declare enum FileType {
|
|
|
18
17
|
* @see http://man7.org/linux/man-pages/man2/stat.2.html
|
|
19
18
|
*/
|
|
20
19
|
export declare class Stats implements StatsBase<number> {
|
|
21
|
-
static
|
|
20
|
+
static Deserialize(data: ArrayBufferLike | ArrayBufferView): Stats;
|
|
22
21
|
/**
|
|
23
22
|
* Clones the stats object.
|
|
24
23
|
*/
|
|
@@ -32,7 +31,7 @@ export declare class Stats implements StatsBase<number> {
|
|
|
32
31
|
blksize: number;
|
|
33
32
|
uid: number;
|
|
34
33
|
gid: number;
|
|
35
|
-
fileData:
|
|
34
|
+
fileData: Uint8Array | null;
|
|
36
35
|
atimeMs: number;
|
|
37
36
|
mtimeMs: number;
|
|
38
37
|
ctimeMs: number;
|
|
@@ -56,7 +55,7 @@ export declare class Stats implements StatsBase<number> {
|
|
|
56
55
|
* @param birthtimeMs time of file creation, in milliseconds since epoch
|
|
57
56
|
*/
|
|
58
57
|
constructor(itemType: FileType, size: number, mode?: number, atimeMs?: number, mtimeMs?: number, ctimeMs?: number, uid?: number, gid?: number, birthtimeMs?: number);
|
|
59
|
-
|
|
58
|
+
serialize(): Uint8Array;
|
|
60
59
|
/**
|
|
61
60
|
* @return [Boolean] True if this item is a file.
|
|
62
61
|
*/
|
package/dist/stats.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Cred } from './cred.js';
|
|
2
|
-
import { Buffer } from 'buffer';
|
|
3
2
|
import { S_IFDIR, S_IFLNK, S_IFMT, S_IFREG } from './emulation/constants.js';
|
|
4
3
|
/**
|
|
5
4
|
* Indicates the type of the given file. Applied to 'mode'.
|
|
@@ -18,8 +17,9 @@ export var FileType;
|
|
|
18
17
|
* @see http://man7.org/linux/man-pages/man2/stat.2.html
|
|
19
18
|
*/
|
|
20
19
|
export class Stats {
|
|
21
|
-
static
|
|
22
|
-
const
|
|
20
|
+
static Deserialize(data) {
|
|
21
|
+
const view = new DataView('buffer' in data ? data.buffer : data);
|
|
22
|
+
const size = view.getUint32(0, true), mode = view.getUint32(4, true), atime = view.getFloat64(8, true), mtime = view.getFloat64(16, true), ctime = view.getFloat64(24, true), uid = view.getUint32(32, true), gid = view.getUint32(36, true);
|
|
23
23
|
return new Stats(mode & S_IFMT, size, mode & ~S_IFMT, atime, mtime, ctime, uid, gid);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -125,16 +125,16 @@ export class Stats {
|
|
|
125
125
|
this.mode |= itemType;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
128
|
+
serialize() {
|
|
129
|
+
const data = new Uint8Array(32), view = new DataView(data.buffer);
|
|
130
|
+
view.setUint32(0, this.size, true);
|
|
131
|
+
view.setUint32(4, this.mode, true);
|
|
132
|
+
view.setFloat64(8, this.atime.getTime(), true);
|
|
133
|
+
view.setFloat64(16, this.mtime.getTime(), true);
|
|
134
|
+
view.setFloat64(24, this.ctime.getTime(), true);
|
|
135
|
+
view.setUint32(32, this.uid, true);
|
|
136
|
+
view.setUint32(36, this.gid, true);
|
|
137
|
+
return data;
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* @return [Boolean] True if this item is a file.
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
3
|
/**
|
|
3
4
|
* Grab bag of utility functions used across the code.
|
|
4
5
|
*/
|
|
5
6
|
import { FileSystem } from './filesystem.js';
|
|
6
7
|
import { Cred } from './cred.js';
|
|
7
8
|
import type { BaseBackendConstructor } from './backends/backend.js';
|
|
9
|
+
import type { TextEncoder as TextEncoderType, TextDecoder as TextDecoderType } from 'node:util';
|
|
8
10
|
/**
|
|
9
11
|
* Synchronous recursive makedir.
|
|
10
12
|
* @internal
|
|
@@ -30,11 +32,14 @@ export declare const setImmediate: typeof globalThis.setImmediate | ((cb: any) =
|
|
|
30
32
|
* @internal
|
|
31
33
|
*/
|
|
32
34
|
export declare const ROOT_NODE_ID: string;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export declare
|
|
35
|
+
declare global {
|
|
36
|
+
const TextEncoder: typeof TextEncoderType;
|
|
37
|
+
const TextDecoder: typeof TextDecoderType;
|
|
38
|
+
}
|
|
39
|
+
export declare const encode: (input?: string) => Uint8Array;
|
|
40
|
+
export declare const decode: (input?: ArrayBuffer | NodeJS.ArrayBufferView, options?: {
|
|
41
|
+
stream?: boolean;
|
|
42
|
+
}) => string;
|
|
38
43
|
/**
|
|
39
44
|
* Generates a random ID.
|
|
40
45
|
* @internal
|
package/dist/utils.js
CHANGED
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { ErrorCode, ApiError } from './ApiError.js';
|
|
11
11
|
import * as path from './emulation/path.js';
|
|
12
|
-
import { Buffer } from 'buffer';
|
|
13
12
|
/**
|
|
14
13
|
* Synchronous recursive makedir.
|
|
15
14
|
* @internal
|
|
@@ -213,13 +212,8 @@ export const setImmediate = typeof globalThis.setImmediate == 'function' ? globa
|
|
|
213
212
|
* @internal
|
|
214
213
|
*/
|
|
215
214
|
export const ROOT_NODE_ID = '/';
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
* @internal
|
|
219
|
-
*/
|
|
220
|
-
export function getEmptyDirNode() {
|
|
221
|
-
return Buffer.from('{}');
|
|
222
|
-
}
|
|
215
|
+
export const encode = new TextEncoder().encode;
|
|
216
|
+
export const decode = new TextDecoder().decode;
|
|
223
217
|
/**
|
|
224
218
|
* Generates a random ID.
|
|
225
219
|
* @internal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A filesystem in your browser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist",
|
|
@@ -44,12 +44,10 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jest/globals": "^29.5.0",
|
|
47
|
-
"@types/archiver": "~2.1.2",
|
|
48
47
|
"@types/jest": "^29.5.1",
|
|
49
48
|
"@types/node": "^14.18.62",
|
|
50
49
|
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
51
50
|
"@typescript-eslint/parser": "^5.55.0",
|
|
52
|
-
"archiver": "~2.1.1",
|
|
53
51
|
"buffer": "~5.1.0",
|
|
54
52
|
"cross-env": "^7.0.3",
|
|
55
53
|
"esbuild": "^0.17.18",
|