@zenfs/core 1.9.5 → 1.10.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/dist/backends/fetch.d.ts +4 -4
- package/dist/backends/fetch.js +2 -2
- package/dist/backends/index.d.ts +1 -0
- package/dist/backends/index.js +1 -0
- package/dist/backends/memory.d.ts +26 -4
- package/dist/backends/memory.js +19 -3
- package/dist/backends/overlay.d.ts +5 -1
- package/dist/backends/overlay.js +7 -1
- package/dist/backends/passthrough.d.ts +2 -1
- package/dist/backends/passthrough.js +7 -0
- package/dist/backends/single_buffer.d.ts +149 -0
- package/dist/backends/single_buffer.js +498 -0
- package/dist/backends/store/fs.d.ts +5 -1
- package/dist/backends/store/fs.js +10 -0
- package/dist/backends/store/store.d.ts +5 -0
- package/dist/internal/devices.js +3 -1
- package/dist/internal/file_index.d.ts +8 -0
- package/dist/internal/file_index.js +22 -2
- package/dist/internal/index_fs.d.ts +2 -1
- package/dist/internal/index_fs.js +3 -0
- package/dist/internal/inode.d.ts +8 -0
- package/dist/internal/inode.js +8 -0
- package/dist/internal/log.d.ts +6 -5
- package/dist/internal/log.js +48 -7
- package/dist/stats.js +5 -5
- package/dist/vfs/path.js +7 -7
- package/package.json +2 -2
- package/readme.md +1 -4
- package/tests/setup/single-buffer.ts +9 -0
package/dist/backends/fetch.d.ts
CHANGED
|
@@ -16,10 +16,10 @@ export interface FetchOptions extends SharedConfig {
|
|
|
16
16
|
* Defaults to `index.json`.
|
|
17
17
|
*/
|
|
18
18
|
index?: string | IndexData;
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
19
|
+
/**
|
|
20
|
+
* Used as the URL prefix for fetched files.
|
|
21
21
|
*/
|
|
22
|
-
baseUrl
|
|
22
|
+
baseUrl: string;
|
|
23
23
|
/**
|
|
24
24
|
* If true, enables writing to the remote (using post and delete)
|
|
25
25
|
* @default false
|
|
@@ -56,7 +56,7 @@ declare const _Fetch: {
|
|
|
56
56
|
};
|
|
57
57
|
readonly baseUrl: {
|
|
58
58
|
readonly type: "string";
|
|
59
|
-
readonly required:
|
|
59
|
+
readonly required: true;
|
|
60
60
|
};
|
|
61
61
|
readonly requestInit: {
|
|
62
62
|
readonly type: "object";
|
package/dist/backends/fetch.js
CHANGED
|
@@ -88,7 +88,7 @@ const _Fetch = {
|
|
|
88
88
|
name: 'Fetch',
|
|
89
89
|
options: {
|
|
90
90
|
index: { type: ['string', 'object'], required: false },
|
|
91
|
-
baseUrl: { type: 'string', required:
|
|
91
|
+
baseUrl: { type: 'string', required: true },
|
|
92
92
|
requestInit: { type: 'object', required: false },
|
|
93
93
|
remoteWrite: { type: 'boolean', required: false },
|
|
94
94
|
},
|
|
@@ -97,7 +97,7 @@ const _Fetch = {
|
|
|
97
97
|
},
|
|
98
98
|
async create(options) {
|
|
99
99
|
var _a;
|
|
100
|
-
const url = new URL(options.baseUrl
|
|
100
|
+
const url = new URL(options.baseUrl);
|
|
101
101
|
url.pathname = normalizePath(url.pathname);
|
|
102
102
|
let baseUrl = url.toString();
|
|
103
103
|
if (baseUrl.at(-1) == '/')
|
package/dist/backends/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './memory.js';
|
|
|
4
4
|
export * from './overlay.js';
|
|
5
5
|
export * from './passthrough.js';
|
|
6
6
|
export * from './port/fs.js';
|
|
7
|
+
export * from './single_buffer.js';
|
|
7
8
|
export * from './store/fs.js';
|
|
8
9
|
export * from './store/map.js';
|
|
9
10
|
export * from './store/store.js';
|
package/dist/backends/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './memory.js';
|
|
|
4
4
|
export * from './overlay.js';
|
|
5
5
|
export * from './passthrough.js';
|
|
6
6
|
export * from './port/fs.js';
|
|
7
|
+
export * from './single_buffer.js';
|
|
7
8
|
export * from './store/fs.js';
|
|
8
9
|
export * from './store/map.js';
|
|
9
10
|
export * from './store/store.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UsageInfo } from '../internal/filesystem.js';
|
|
1
2
|
import { StoreFS } from './store/fs.js';
|
|
2
3
|
import { SyncMapTransaction, type SyncMapStore } from './store/map.js';
|
|
3
4
|
/**
|
|
@@ -5,24 +6,45 @@ import { SyncMapTransaction, type SyncMapStore } from './store/map.js';
|
|
|
5
6
|
* @category Stores and Transactions
|
|
6
7
|
*/
|
|
7
8
|
export declare class InMemoryStore extends Map<number, Uint8Array> implements SyncMapStore {
|
|
9
|
+
readonly maxSize: number;
|
|
8
10
|
readonly label?: string | undefined;
|
|
9
11
|
readonly flags: readonly [];
|
|
10
12
|
readonly name = "tmpfs";
|
|
11
|
-
constructor(label?: string | undefined);
|
|
13
|
+
constructor(maxSize?: number, label?: string | undefined);
|
|
12
14
|
sync(): Promise<void>;
|
|
13
15
|
transaction(): SyncMapTransaction;
|
|
16
|
+
get bytes(): number;
|
|
17
|
+
usage(): UsageInfo;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for an in-memory backend
|
|
21
|
+
* @category Backends and Configuration
|
|
22
|
+
*/
|
|
23
|
+
export interface InMemoryOptions {
|
|
24
|
+
/** The maximum size of the store. Defaults to 4 GiB */
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
/** The label to use for the store and file system */
|
|
27
|
+
label?: string;
|
|
28
|
+
/** @deprecated use `label` */
|
|
29
|
+
name?: string;
|
|
14
30
|
}
|
|
15
31
|
declare const _InMemory: {
|
|
16
32
|
readonly name: "InMemory";
|
|
17
33
|
readonly options: {
|
|
34
|
+
readonly maxSize: {
|
|
35
|
+
readonly type: "number";
|
|
36
|
+
readonly required: false;
|
|
37
|
+
};
|
|
38
|
+
readonly label: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
readonly required: false;
|
|
41
|
+
};
|
|
18
42
|
readonly name: {
|
|
19
43
|
readonly type: "string";
|
|
20
44
|
readonly required: false;
|
|
21
45
|
};
|
|
22
46
|
};
|
|
23
|
-
readonly create: ({ name }:
|
|
24
|
-
name?: string;
|
|
25
|
-
}) => StoreFS<InMemoryStore>;
|
|
47
|
+
readonly create: ({ maxSize, label, name }: InMemoryOptions) => StoreFS<InMemoryStore>;
|
|
26
48
|
};
|
|
27
49
|
type _InMemory = typeof _InMemory;
|
|
28
50
|
export interface InMemory extends _InMemory {
|
package/dist/backends/memory.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { size_max } from '../vfs/constants.js';
|
|
1
2
|
import { StoreFS } from './store/fs.js';
|
|
2
3
|
import { SyncMapTransaction } from './store/map.js';
|
|
3
4
|
/**
|
|
@@ -5,8 +6,9 @@ import { SyncMapTransaction } from './store/map.js';
|
|
|
5
6
|
* @category Stores and Transactions
|
|
6
7
|
*/
|
|
7
8
|
export class InMemoryStore extends Map {
|
|
8
|
-
constructor(label) {
|
|
9
|
+
constructor(maxSize = size_max, label) {
|
|
9
10
|
super();
|
|
11
|
+
this.maxSize = maxSize;
|
|
10
12
|
this.label = label;
|
|
11
13
|
this.flags = [];
|
|
12
14
|
this.name = 'tmpfs';
|
|
@@ -15,14 +17,28 @@ export class InMemoryStore extends Map {
|
|
|
15
17
|
transaction() {
|
|
16
18
|
return new SyncMapTransaction(this);
|
|
17
19
|
}
|
|
20
|
+
get bytes() {
|
|
21
|
+
let size = this.size * 4;
|
|
22
|
+
for (const data of this.values())
|
|
23
|
+
size += data.byteLength;
|
|
24
|
+
return size;
|
|
25
|
+
}
|
|
26
|
+
usage() {
|
|
27
|
+
return {
|
|
28
|
+
totalSpace: this.maxSize,
|
|
29
|
+
freeSpace: this.maxSize - this.bytes,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
18
32
|
}
|
|
19
33
|
const _InMemory = {
|
|
20
34
|
name: 'InMemory',
|
|
21
35
|
options: {
|
|
36
|
+
maxSize: { type: 'number', required: false },
|
|
37
|
+
label: { type: 'string', required: false },
|
|
22
38
|
name: { type: 'string', required: false },
|
|
23
39
|
},
|
|
24
|
-
create({ name }) {
|
|
25
|
-
const fs = new StoreFS(new InMemoryStore(name));
|
|
40
|
+
create({ maxSize, label, name }) {
|
|
41
|
+
const fs = new StoreFS(new InMemoryStore(maxSize, label !== null && label !== void 0 ? label : name));
|
|
26
42
|
fs.checkRootSync();
|
|
27
43
|
return fs;
|
|
28
44
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { File } from '../internal/file.js';
|
|
2
|
-
import type { CreationOptions } from '../internal/filesystem.js';
|
|
2
|
+
import type { CreationOptions, UsageInfo } from '../internal/filesystem.js';
|
|
3
3
|
import type { Stats } from '../stats.js';
|
|
4
4
|
import type { InodeLike } from '../internal/inode.js';
|
|
5
5
|
import { FileSystem } from '../internal/filesystem.js';
|
|
@@ -37,6 +37,10 @@ export declare class OverlayFS extends FileSystem {
|
|
|
37
37
|
private _deleteLogError?;
|
|
38
38
|
private _ready;
|
|
39
39
|
constructor({ writable, readable }: OverlayOptions);
|
|
40
|
+
/**
|
|
41
|
+
* @todo Consider trying to track information on the writable as well
|
|
42
|
+
*/
|
|
43
|
+
usage(): UsageInfo;
|
|
40
44
|
sync(path: string, data: Uint8Array, stats: Readonly<InodeLike>): Promise<void>;
|
|
41
45
|
syncSync(path: string, data: Uint8Array, stats: Readonly<InodeLike>): void;
|
|
42
46
|
read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void>;
|
package/dist/backends/overlay.js
CHANGED
|
@@ -86,10 +86,16 @@ export class OverlayFS extends FileSystem {
|
|
|
86
86
|
this.writable = writable;
|
|
87
87
|
this.readable = readable;
|
|
88
88
|
if (this.writable.attributes.has('no_write')) {
|
|
89
|
-
throw err(new ErrnoError(Errno.EINVAL, 'Writable file can not be written to'));
|
|
89
|
+
throw err(new ErrnoError(Errno.EINVAL, 'Writable file system can not be written to'));
|
|
90
90
|
}
|
|
91
91
|
this._ready = this._initialize();
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* @todo Consider trying to track information on the writable as well
|
|
95
|
+
*/
|
|
96
|
+
usage() {
|
|
97
|
+
return this.readable.usage();
|
|
98
|
+
}
|
|
93
99
|
async sync(path, data, stats) {
|
|
94
100
|
await this.copyForWrite(path);
|
|
95
101
|
await this.writable.sync(path, data, stats);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as fs from 'node:fs';
|
|
2
2
|
import { File } from '../internal/file.js';
|
|
3
|
-
import { FileSystem } from '../internal/filesystem.js';
|
|
3
|
+
import { FileSystem, type UsageInfo } from '../internal/filesystem.js';
|
|
4
4
|
import type { InodeLike } from '../internal/inode.js';
|
|
5
5
|
import { Stats } from '../stats.js';
|
|
6
6
|
export type NodeFS = typeof fs;
|
|
@@ -16,6 +16,7 @@ export declare class PassthroughFS extends FileSystem {
|
|
|
16
16
|
readonly nodeFS: NodeFS;
|
|
17
17
|
readonly prefix: string;
|
|
18
18
|
constructor(nodeFS: NodeFS, prefix: string);
|
|
19
|
+
usage(): UsageInfo;
|
|
19
20
|
path(path: string): string;
|
|
20
21
|
error(err: unknown, path: string): never;
|
|
21
22
|
/**
|
|
@@ -141,6 +141,13 @@ export class PassthroughFS extends FileSystem {
|
|
|
141
141
|
this.nodeFS = nodeFS;
|
|
142
142
|
this.prefix = prefix;
|
|
143
143
|
}
|
|
144
|
+
usage() {
|
|
145
|
+
const info = this.nodeFS.statfsSync(this.prefix);
|
|
146
|
+
return {
|
|
147
|
+
totalSpace: info.bsize * info.blocks,
|
|
148
|
+
freeSpace: info.bsize * info.bfree,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
144
151
|
path(path) {
|
|
145
152
|
return join(this.prefix, path.slice(1));
|
|
146
153
|
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { UsageInfo } from '../internal/filesystem.js';
|
|
2
|
+
import { StoreFS } from './store/fs.js';
|
|
3
|
+
import { SyncMapTransaction, type SyncMapStore } from './store/map.js';
|
|
4
|
+
import type { Store } from './store/store.js';
|
|
5
|
+
declare class MetadataEntry {
|
|
6
|
+
/** Inode or data ID */
|
|
7
|
+
id: number;
|
|
8
|
+
/** Reserved for 64-bit offset expansion */
|
|
9
|
+
protected offset_: number;
|
|
10
|
+
/** Offset into the buffer the data is stored at. */
|
|
11
|
+
offset: number;
|
|
12
|
+
/** The size of the data */
|
|
13
|
+
size: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A block of metadata for a single-buffer file system.
|
|
17
|
+
* This metadata maps IDs (for inodes and data) to actual offsets in the buffer.
|
|
18
|
+
* This is done since IDs are not guaranteed to be sequential.
|
|
19
|
+
*/
|
|
20
|
+
declare class MetadataBlock {
|
|
21
|
+
protected readonly superblock: SuperBlock;
|
|
22
|
+
offset: number;
|
|
23
|
+
constructor(superblock: SuperBlock, offset?: number);
|
|
24
|
+
/**
|
|
25
|
+
* The crc32c checksum for the metadata block.
|
|
26
|
+
* @privateRemarks Keep this first!
|
|
27
|
+
*/
|
|
28
|
+
checksum: number;
|
|
29
|
+
/** The (last) time this metadata block was updated */
|
|
30
|
+
timestamp: number;
|
|
31
|
+
/** Reserved for 64-bit offset expansion */
|
|
32
|
+
protected previous_offset_: number;
|
|
33
|
+
/** Offset to the previous metadata block */
|
|
34
|
+
previous_offset: number;
|
|
35
|
+
protected _previous?: MetadataBlock;
|
|
36
|
+
get previous(): MetadataBlock | undefined;
|
|
37
|
+
/** Metadata entries. */
|
|
38
|
+
entries: MetadataEntry[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The super block structure for a single-buffer file system
|
|
42
|
+
*/
|
|
43
|
+
declare class SuperBlock {
|
|
44
|
+
readonly store: SingleBufferStore;
|
|
45
|
+
constructor(store: SingleBufferStore);
|
|
46
|
+
/**
|
|
47
|
+
* The crc32c checksum for the super block.
|
|
48
|
+
* @privateRemarks Keep this first!
|
|
49
|
+
*/
|
|
50
|
+
checksum: number;
|
|
51
|
+
/** Signature for the superblock. */
|
|
52
|
+
magic: number;
|
|
53
|
+
/** The version of the on-disk format */
|
|
54
|
+
version: number;
|
|
55
|
+
/** Which format of `Inode` is used */
|
|
56
|
+
inode_format: number;
|
|
57
|
+
/** Flags for the file system. Currently unused */
|
|
58
|
+
flags: number;
|
|
59
|
+
/** The number of used bytes, including the super block and metadata */
|
|
60
|
+
used_bytes: bigint;
|
|
61
|
+
/** The total size of the entire file system, including the super block and metadata */
|
|
62
|
+
total_bytes: bigint;
|
|
63
|
+
/** An ID for this file system */
|
|
64
|
+
id: bigint;
|
|
65
|
+
/**
|
|
66
|
+
* The size in bytes of a metadata block.
|
|
67
|
+
* Not currently configurable.
|
|
68
|
+
*/
|
|
69
|
+
metadata_block_size: number;
|
|
70
|
+
/** Reserved for 64-bit offset expansion */
|
|
71
|
+
protected metadata_offset_: number;
|
|
72
|
+
/** Offset of the current metadata block */
|
|
73
|
+
metadata_offset: number;
|
|
74
|
+
metadata: MetadataBlock;
|
|
75
|
+
/** An optional label for the file system */
|
|
76
|
+
label: string;
|
|
77
|
+
/** Padded to 256 bytes */
|
|
78
|
+
_padding: number[];
|
|
79
|
+
/**
|
|
80
|
+
* Rotate out the current metadata block.
|
|
81
|
+
* Allocates a new metadata block, moves the current one to backup,
|
|
82
|
+
* and updates used_bytes accordingly.
|
|
83
|
+
* @returns the new metadata block
|
|
84
|
+
*/
|
|
85
|
+
rotateMetadata(): MetadataBlock;
|
|
86
|
+
/**
|
|
87
|
+
* Checks to see if `length` bytes are unused, starting at `offset`.
|
|
88
|
+
* @internal Not for external use!
|
|
89
|
+
*/
|
|
90
|
+
isUnused(offset: number, length: number): boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
* @category Stores and Transactions
|
|
95
|
+
*/
|
|
96
|
+
export declare class SingleBufferStore implements SyncMapStore {
|
|
97
|
+
readonly flags: readonly [];
|
|
98
|
+
readonly name = "sbfs";
|
|
99
|
+
readonly id = 1935828595;
|
|
100
|
+
protected superblock: SuperBlock;
|
|
101
|
+
/**
|
|
102
|
+
* @internal @hidden
|
|
103
|
+
*/
|
|
104
|
+
readonly _view: DataView;
|
|
105
|
+
/**
|
|
106
|
+
* @internal @hidden
|
|
107
|
+
*/
|
|
108
|
+
readonly _buffer: Uint8Array;
|
|
109
|
+
constructor(buffer: ArrayBufferLike | ArrayBufferView);
|
|
110
|
+
/**
|
|
111
|
+
* Update a block's checksum and write it to the store's buffer.
|
|
112
|
+
* @internal @hidden
|
|
113
|
+
*/
|
|
114
|
+
_write(value: SuperBlock | MetadataBlock): void;
|
|
115
|
+
keys(): Iterable<number>;
|
|
116
|
+
get(id: number): Uint8Array | undefined;
|
|
117
|
+
set(id: number, data: Uint8Array): void;
|
|
118
|
+
delete(id: number): void;
|
|
119
|
+
_fs?: StoreFS<Store> | undefined;
|
|
120
|
+
sync(): Promise<void>;
|
|
121
|
+
usage(): UsageInfo;
|
|
122
|
+
transaction(): SyncMapTransaction;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Options for the `SingleBuffer` backend
|
|
126
|
+
* @category Backends and Configuration
|
|
127
|
+
*/
|
|
128
|
+
export interface SingleBufferOptions {
|
|
129
|
+
buffer: ArrayBufferLike | ArrayBufferView;
|
|
130
|
+
}
|
|
131
|
+
declare const _SingleBuffer: {
|
|
132
|
+
readonly name: "SingleBuffer";
|
|
133
|
+
readonly options: {
|
|
134
|
+
readonly buffer: {
|
|
135
|
+
readonly type: "object";
|
|
136
|
+
readonly required: true;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
readonly create: ({ buffer }: SingleBufferOptions) => StoreFS<SingleBufferStore>;
|
|
140
|
+
};
|
|
141
|
+
type _SingleBuffer = typeof _SingleBuffer;
|
|
142
|
+
export interface SingleBuffer extends _SingleBuffer {
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* A backend that uses a single buffer for storing data
|
|
146
|
+
* @category Backends and Configuration
|
|
147
|
+
*/
|
|
148
|
+
export declare const SingleBuffer: SingleBuffer;
|
|
149
|
+
export {};
|