core-3nweb-client-lib 0.20.7 → 0.22.0
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/build/api-defs/common-caps.d.ts +0 -1
- package/build/api-defs/files.d.ts +8 -7
- package/build/api-defs/startup.d.ts +0 -1
- package/build/core/asmail/inbox/attachments/fs.d.ts +2 -2
- package/build/core/asmail/inbox/attachments/fs.js +3 -2
- package/build/core/asmail/msg/common.d.ts +2 -2
- package/build/core/asmail/msg/common.js +3 -2
- package/build/core/asmail/msg/opener.d.ts +2 -2
- package/build/core/asmail/msg/opener.js +3 -2
- package/build/core/asmail/msg/packer.d.ts +2 -2
- package/build/core/asmail/msg/packer.js +7 -6
- package/build/core/index.d.ts +3 -3
- package/build/core/index.js +24 -31
- package/build/core/storage/index.js +2 -2
- package/build/core/storage/local/obj-files.js +8 -5
- package/build/core/storage/local/obj-status.js +4 -3
- package/build/core/storage/synced/obj-status.js +4 -3
- package/build/core-ipc/startup-caps.js +0 -3
- package/build/ipc-via-protobuf/bytes.js +1 -1
- package/build/lib-client/3nstorage/xsp-fs/attrs.d.ts +28 -0
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +337 -0
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/common.js +3 -2
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +31 -18
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +130 -118
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +0 -1
- package/build/lib-client/3nstorage/xsp-fs/file.js +14 -49
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +95 -91
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +19 -24
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +133 -190
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +3 -4
- package/build/lib-client/3nstorage/xsp-fs/fs.js +18 -21
- package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +13 -8
- package/build/lib-client/3nstorage/xsp-fs/link-node.js +46 -38
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +17 -35
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +34 -127
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +57 -0
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +182 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.d.ts +3 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +87 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.d.ts +6 -0
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +1022 -0
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/local-files/device-fs.js +7 -3
- package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +8 -7
- package/build/lib-common/big-endian.d.ts +0 -24
- package/build/lib-common/big-endian.js +16 -78
- package/build/lib-common/exceptions/file.js +5 -1
- package/build/lib-common/obj-streaming/sink-utils.d.ts +0 -4
- package/build/lib-common/obj-streaming/sink-utils.js +4 -70
- package/build/lib-common/objs-on-disk/file-layout.js +2 -1
- package/build/lib-common/objs-on-disk/obj-file.js +2 -2
- package/build/lib-common/objs-on-disk/utils.js +2 -1
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +2 -1
- package/build/lib-index.d.ts +1 -0
- package/build/lib-index.js +3 -0
- package/package.json +2 -2
- package/build/lib-client/files/file-attrs.d.ts +0 -76
- package/build/lib-client/files/file-attrs.js +0 -549
- package/build/lib-client/files/file-layout.d.ts +0 -56
- package/build/lib-client/files/file-layout.js +0 -456
- package/build/lib-client/files/file-sink.d.ts +0 -33
- package/build/lib-client/files/file-sink.js +0 -173
- package/build/lib-client/files/file-source.d.ts +0 -19
- package/build/lib-client/files/file-source.js +0 -115
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2020, 2022 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.XAttrs = exports.CommonAttrs = void 0;
|
|
20
|
+
const assert_1 = require("../../../lib-common/assert");
|
|
21
|
+
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
22
|
+
const big_endian_1 = require("../../../lib-common/big-endian");
|
|
23
|
+
class CommonAttrs {
|
|
24
|
+
constructor(ctime, mtime) {
|
|
25
|
+
this.ctime = ctime;
|
|
26
|
+
this.mtime = mtime;
|
|
27
|
+
Object.seal(this);
|
|
28
|
+
}
|
|
29
|
+
static makeForTimeNow() {
|
|
30
|
+
const now = Date.now();
|
|
31
|
+
return new CommonAttrs(now, now);
|
|
32
|
+
}
|
|
33
|
+
static fromAttrs(attrs) {
|
|
34
|
+
return new CommonAttrs(attrs.ctime, attrs.mtime);
|
|
35
|
+
}
|
|
36
|
+
static parse(bytes) {
|
|
37
|
+
if (bytes.length < CommonAttrs.PACK_LEN) {
|
|
38
|
+
throw parsingException(`byte array is too short`);
|
|
39
|
+
}
|
|
40
|
+
const ctime = big_endian_1.uintFrom6Bytes(bytes, 0);
|
|
41
|
+
const mtime = big_endian_1.uintFrom6Bytes(bytes, 6);
|
|
42
|
+
return new CommonAttrs(ctime, mtime);
|
|
43
|
+
}
|
|
44
|
+
pack() {
|
|
45
|
+
const bytes = Buffer.allocUnsafe(CommonAttrs.PACK_LEN);
|
|
46
|
+
big_endian_1.packUintTo6Bytes(this.ctime, bytes, 0);
|
|
47
|
+
big_endian_1.packUintTo6Bytes(this.mtime, bytes, 6);
|
|
48
|
+
return bytes;
|
|
49
|
+
}
|
|
50
|
+
copy() {
|
|
51
|
+
return new CommonAttrs(this.ctime, this.mtime);
|
|
52
|
+
}
|
|
53
|
+
updateMTime() {
|
|
54
|
+
this.mtime = Date.now();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.CommonAttrs = CommonAttrs;
|
|
58
|
+
CommonAttrs.PACK_LEN = 6 + 6;
|
|
59
|
+
Object.freeze(CommonAttrs.prototype);
|
|
60
|
+
Object.freeze(CommonAttrs);
|
|
61
|
+
class XAttrs {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.attrs = new Map();
|
|
64
|
+
Object.seal(this);
|
|
65
|
+
}
|
|
66
|
+
static makeEmpty() {
|
|
67
|
+
return new XAttrs();
|
|
68
|
+
}
|
|
69
|
+
static parseFrom(sections) {
|
|
70
|
+
const xattrs = new XAttrs();
|
|
71
|
+
for (const bytes of sections) {
|
|
72
|
+
let i = 0;
|
|
73
|
+
while (i < bytes.length) {
|
|
74
|
+
const { bytesRead, binVal, strVal, jsonVal, xaName } = extAttrs.readNamedAttr(buffer_utils_1.toBuffer(bytes), i);
|
|
75
|
+
xattrs.attrs.set(xaName, { binVal, strVal, jsonVal });
|
|
76
|
+
i += bytesRead;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return xattrs;
|
|
80
|
+
}
|
|
81
|
+
copy() {
|
|
82
|
+
const copy = new XAttrs();
|
|
83
|
+
for (const [xaName, xaVal] of this.attrs.entries()) {
|
|
84
|
+
copy.attrs.set(xaName, xaVal);
|
|
85
|
+
}
|
|
86
|
+
return copy;
|
|
87
|
+
}
|
|
88
|
+
makeUpdated(changes) {
|
|
89
|
+
const updated = this.copy();
|
|
90
|
+
if (changes.remove && (changes.remove.length > 0)) {
|
|
91
|
+
for (const xaName of changes.remove) {
|
|
92
|
+
updated.attrs.delete(xaName);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (changes.set && (Object.keys(changes.set).length > 0)) {
|
|
96
|
+
for (const [xaName, value] of Object.entries(changes.set)) {
|
|
97
|
+
if (typeof value === 'string') {
|
|
98
|
+
updated.attrs.set(xaName, { strVal: value });
|
|
99
|
+
}
|
|
100
|
+
else if (Buffer.isBuffer(value) || ArrayBuffer.isView(value)) {
|
|
101
|
+
updated.attrs.set(xaName, { binVal: value });
|
|
102
|
+
}
|
|
103
|
+
else if (value !== undefined) {
|
|
104
|
+
updated.attrs.set(xaName, { jsonVal: value });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return updated;
|
|
109
|
+
}
|
|
110
|
+
get(xaName) {
|
|
111
|
+
const val = this.attrs.get(xaName);
|
|
112
|
+
if (!val) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
else if (val.strVal !== undefined) {
|
|
116
|
+
return val.strVal;
|
|
117
|
+
}
|
|
118
|
+
else if (val.binVal) {
|
|
119
|
+
return val.binVal;
|
|
120
|
+
}
|
|
121
|
+
else if (val.jsonVal !== undefined) {
|
|
122
|
+
return val.jsonVal;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
list() {
|
|
126
|
+
return Array.from(this.attrs.keys());
|
|
127
|
+
}
|
|
128
|
+
get isEmpty() {
|
|
129
|
+
return (this.attrs.size === 0);
|
|
130
|
+
}
|
|
131
|
+
pack() {
|
|
132
|
+
if (this.isEmpty) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const bytes = [];
|
|
136
|
+
for (const [xaName, v] of this.attrs.entries()) {
|
|
137
|
+
if (v.strVal !== undefined) {
|
|
138
|
+
bytes.push(extAttrs.packNamedStrAttr(xaName, v.strVal));
|
|
139
|
+
}
|
|
140
|
+
else if (v.binVal) {
|
|
141
|
+
bytes.push(extAttrs.packNamedBinaryAttr(xaName, v.binVal));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
assert_1.assert(v.jsonVal !== undefined);
|
|
145
|
+
bytes.push(extAttrs.packNamedJsonAttr(xaName, v.jsonVal));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return bytes;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.XAttrs = XAttrs;
|
|
152
|
+
Object.freeze(XAttrs.prototype);
|
|
153
|
+
Object.freeze(XAttrs);
|
|
154
|
+
var extAttrs;
|
|
155
|
+
(function (extAttrs) {
|
|
156
|
+
const NAMED_BINARY = 1;
|
|
157
|
+
const NAMED_UTF8_STR = 2;
|
|
158
|
+
const NAMED_JSON = 3;
|
|
159
|
+
function readNamedAttr(bytes, i) {
|
|
160
|
+
const t = parseTypeByte(bytes[i]);
|
|
161
|
+
let ofs = i + 1;
|
|
162
|
+
const nameLen = readLenNum(bytes, ofs, t.nameLen);
|
|
163
|
+
ofs += t.nameLen;
|
|
164
|
+
const contentLen = readLenNum(bytes, ofs, t.contentLen);
|
|
165
|
+
ofs += t.contentLen;
|
|
166
|
+
const xaName = bytes.slice(ofs, ofs + nameLen).toString('utf8');
|
|
167
|
+
ofs += nameLen;
|
|
168
|
+
const bytesRead = ofs - i + contentLen;
|
|
169
|
+
if ((contentLen === 0) || (bytes.length < (i + bytesRead))) {
|
|
170
|
+
throw parsingException(`Unexpected end of byte array`);
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
if (t.type === NAMED_UTF8_STR) {
|
|
174
|
+
return {
|
|
175
|
+
bytesRead, xaName,
|
|
176
|
+
strVal: bytes.slice(ofs, ofs + contentLen).toString('utf8'),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
else if (t.type === NAMED_JSON) {
|
|
180
|
+
return {
|
|
181
|
+
bytesRead, xaName,
|
|
182
|
+
jsonVal: JSON.parse(buffer_utils_1.toBuffer(bytes).slice(ofs, ofs + contentLen).toString('utf8')),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
else if (t.type === NAMED_BINARY) {
|
|
186
|
+
return {
|
|
187
|
+
bytesRead, xaName,
|
|
188
|
+
binVal: bytes.slice(ofs, ofs + contentLen),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
throw new Error(`Unknown type ${t.type} of named attribute`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
throw parsingException(`Error in parsing `, err);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
extAttrs.readNamedAttr = readNamedAttr;
|
|
200
|
+
function parseTypeByte(b) {
|
|
201
|
+
const type = ((b & 0b11111000) >> 5);
|
|
202
|
+
const nameLen = ((b & 0b00000100) >> 2) + 1;
|
|
203
|
+
const contentLen = (b & 0b00000011) + 1;
|
|
204
|
+
return { type, contentLen, nameLen };
|
|
205
|
+
}
|
|
206
|
+
function readLenNum(bytes, i, len) {
|
|
207
|
+
switch (len) {
|
|
208
|
+
case 1:
|
|
209
|
+
return bytes[i];
|
|
210
|
+
case 2:
|
|
211
|
+
return big_endian_1.uintFrom2Bytes(bytes, i);
|
|
212
|
+
case 3:
|
|
213
|
+
return big_endian_1.uintFrom3Bytes(bytes, i);
|
|
214
|
+
case 4:
|
|
215
|
+
return big_endian_1.uintFrom4Bytes(bytes, i);
|
|
216
|
+
default:
|
|
217
|
+
throw parsingException(`Too many bytes for xattr length`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function packNamedStrAttr(name, value) {
|
|
221
|
+
assert_1.assert((typeof name === 'string') && (name.length > 0) &&
|
|
222
|
+
(typeof value === 'string') && (value.length > 0));
|
|
223
|
+
const nameBin = Buffer.from(name, 'utf8');
|
|
224
|
+
const valueBin = Buffer.from(value, 'utf8');
|
|
225
|
+
return packNamedAttr(NAMED_UTF8_STR, nameBin, valueBin);
|
|
226
|
+
}
|
|
227
|
+
extAttrs.packNamedStrAttr = packNamedStrAttr;
|
|
228
|
+
function packNamedBinaryAttr(name, value) {
|
|
229
|
+
assert_1.assert((typeof name === 'string') && (name.length > 0) &&
|
|
230
|
+
(value.length > 0));
|
|
231
|
+
const nameBin = Buffer.from(name, 'utf8');
|
|
232
|
+
return packNamedAttr(NAMED_BINARY, nameBin, value);
|
|
233
|
+
}
|
|
234
|
+
extAttrs.packNamedBinaryAttr = packNamedBinaryAttr;
|
|
235
|
+
function packNamedJsonAttr(name, value) {
|
|
236
|
+
assert_1.assert((typeof name === 'string') && (name.length > 0) &&
|
|
237
|
+
(value !== undefined));
|
|
238
|
+
const nameBin = Buffer.from(name, 'utf8');
|
|
239
|
+
const valueBin = Buffer.from(JSON.stringify(value), 'utf8');
|
|
240
|
+
return packNamedAttr(NAMED_JSON, nameBin, valueBin);
|
|
241
|
+
}
|
|
242
|
+
extAttrs.packNamedJsonAttr = packNamedJsonAttr;
|
|
243
|
+
function packNamedAttr(type, name, value) {
|
|
244
|
+
const nameLenLen = byteToStoreLen(name.length);
|
|
245
|
+
if (nameLenLen > 2) {
|
|
246
|
+
throw new Error(`Name is too long to pack`);
|
|
247
|
+
}
|
|
248
|
+
const contentLenLen = byteToStoreLen(value.length);
|
|
249
|
+
if (contentLenLen > 4) {
|
|
250
|
+
throw new Error(`Value is too long to pack`);
|
|
251
|
+
}
|
|
252
|
+
const b = Buffer.allocUnsafe(1 + nameLenLen + contentLenLen + name.length + value.length);
|
|
253
|
+
// first byte contains, left to right:
|
|
254
|
+
// - 5 bits with type,
|
|
255
|
+
// - 1 bits with number of bytes for name length, and
|
|
256
|
+
// - 2 bits with number of bytes for value length
|
|
257
|
+
b[0] = (type << 3) | ((nameLenLen - 1) << 2) | (contentLenLen - 1);
|
|
258
|
+
// bytes with length of name
|
|
259
|
+
let i = 1;
|
|
260
|
+
packUint(name.length, b, i, nameLenLen);
|
|
261
|
+
// bytes with length of content
|
|
262
|
+
i += nameLenLen;
|
|
263
|
+
packUint(value.length, b, i, contentLenLen);
|
|
264
|
+
// bytes with name
|
|
265
|
+
i += contentLenLen;
|
|
266
|
+
b.set(name, i);
|
|
267
|
+
// bytes with content
|
|
268
|
+
i += name.length;
|
|
269
|
+
b.set(value, i);
|
|
270
|
+
return b;
|
|
271
|
+
}
|
|
272
|
+
function byteToStoreLen(len) {
|
|
273
|
+
if (len <= 0xff) {
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
276
|
+
else if (len <= 0xffff) {
|
|
277
|
+
return 2;
|
|
278
|
+
}
|
|
279
|
+
else if (len <= 0xffffff) {
|
|
280
|
+
return 3;
|
|
281
|
+
}
|
|
282
|
+
else if (len <= 0xffffffff) {
|
|
283
|
+
return 4;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
return 5;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function packUint(u, b, i, byteToUse) {
|
|
290
|
+
switch (byteToUse) {
|
|
291
|
+
case 1:
|
|
292
|
+
b[i] = u;
|
|
293
|
+
break;
|
|
294
|
+
case 2:
|
|
295
|
+
big_endian_1.packUintTo2Bytes(u, b, i);
|
|
296
|
+
break;
|
|
297
|
+
case 3:
|
|
298
|
+
big_endian_1.packUintTo3Bytes(u, b, i);
|
|
299
|
+
break;
|
|
300
|
+
case 4:
|
|
301
|
+
big_endian_1.packUintTo4Bytes(u, b, i);
|
|
302
|
+
break;
|
|
303
|
+
default:
|
|
304
|
+
assert_1.assert(false);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// export function pack(xattrs: XAttrs): Buffer {
|
|
308
|
+
// const ext: Buffer[] = [];
|
|
309
|
+
// for (const xattr of Object.values(xattrs)) {
|
|
310
|
+
// if (xattr.type === 'named-utf8str') {
|
|
311
|
+
// ext.push(packNamedStrAttr(xattr.name, xattr.value));
|
|
312
|
+
// } else if (xattr.type === 'named-json') {
|
|
313
|
+
// ext.push(packNamedJsonAttr(xattr.name, xattr.value));
|
|
314
|
+
// } else if (xattr.type === 'named-binary') {
|
|
315
|
+
// ext.push(packNamedBinaryAttr(xattr.name, xattr.value));
|
|
316
|
+
// } else {
|
|
317
|
+
// throw new Error(`Unknown type of named attribute`);
|
|
318
|
+
// }
|
|
319
|
+
// }
|
|
320
|
+
// const bytes = Buffer.allocUnsafe(ext.reduce((len, b) => len+b.length, 0));
|
|
321
|
+
// let ofs = 0;
|
|
322
|
+
// for (const buf of ext) {
|
|
323
|
+
// bytes.set(buf, ofs);
|
|
324
|
+
// ofs += buf.length;
|
|
325
|
+
// }
|
|
326
|
+
// return bytes;
|
|
327
|
+
// }
|
|
328
|
+
})(extAttrs || (extAttrs = {}));
|
|
329
|
+
Object.freeze(extAttrs);
|
|
330
|
+
function parsingException(msg, cause) {
|
|
331
|
+
return {
|
|
332
|
+
runtimeException: true,
|
|
333
|
+
type: 'attrs-parsing',
|
|
334
|
+
cause, msg
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
Object.freeze(exports);
|
|
@@ -2,7 +2,7 @@ import { ScryptGenParams } from '../../key-derivation';
|
|
|
2
2
|
import { AsyncSBoxCryptor, Subscribe, ObjSource } from 'xsp-files';
|
|
3
3
|
import { objChanged, objRemoved } from '../../../lib-common/service-api/3nstorage/owner';
|
|
4
4
|
export { AsyncSBoxCryptor } from 'xsp-files';
|
|
5
|
-
export {
|
|
5
|
+
export { FolderInJSON } from './folder-node';
|
|
6
6
|
declare type StorageType = web3n.files.FSType;
|
|
7
7
|
export interface RemoteObjRemovalEvent extends objRemoved.Event {
|
|
8
8
|
type: 'remote-delete';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2017, 2019 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2017, 2019 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.wrapSyncStorageImplementation = exports.wrapStorageImplementation = exports.NodesContainer = void 0;
|
|
19
20
|
/**
|
|
@@ -2,28 +2,34 @@
|
|
|
2
2
|
* Everything in this module is assumed to be inside of a file system
|
|
3
3
|
* reliance set.
|
|
4
4
|
*/
|
|
5
|
-
import { NodeInFS
|
|
5
|
+
import { NodeInFS } from './node-in-fs';
|
|
6
6
|
import { LinkParameters } from '../../files';
|
|
7
7
|
import { Storage, AsyncSBoxCryptor } from './common';
|
|
8
|
-
import { Subscribe, ObjSource
|
|
9
|
-
import {
|
|
8
|
+
import { Subscribe, ObjSource } from 'xsp-files';
|
|
9
|
+
import { CommonAttrs, XAttrs } from './attrs';
|
|
10
|
+
import { NodePersistance } from './node-persistence';
|
|
10
11
|
declare type FileByteSource = web3n.files.FileByteSource;
|
|
11
12
|
declare type FileByteSink = web3n.files.FileByteSink;
|
|
12
|
-
declare
|
|
13
|
+
declare type XAttrsChanges = web3n.files.XAttrsChanges;
|
|
14
|
+
interface FileAttrs {
|
|
15
|
+
attrs: CommonAttrs;
|
|
16
|
+
size: number;
|
|
17
|
+
xattrs?: XAttrs;
|
|
18
|
+
}
|
|
19
|
+
declare class FilePersistance extends NodePersistance {
|
|
13
20
|
constructor(zNonce: Uint8Array, key: Uint8Array, cryptor: AsyncSBoxCryptor);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
getAttrs(objSrc: ObjSource): Promise<FileAttrs>;
|
|
22
|
+
getFileSource(objSrc: ObjSource, getAttrs?: boolean): Promise<{
|
|
23
|
+
src: FileByteSource;
|
|
24
|
+
fileAttrs?: FileAttrs;
|
|
18
25
|
}>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
readBytes(objSrc: ObjSource, start: number | undefined, end: number | undefined, getAttrs?: boolean): Promise<{
|
|
27
|
+
bytes?: Uint8Array;
|
|
28
|
+
fileAttrs?: FileAttrs;
|
|
22
29
|
}>;
|
|
23
|
-
saveBytes(bytes: Uint8Array | Uint8Array[], version: number, attrs:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
cancelSinkDef: (err: any) => void;
|
|
30
|
+
saveBytes(bytes: Uint8Array | Uint8Array[], version: number, attrs: CommonAttrs, xattrs: XAttrs | undefined): Promise<Subscribe>;
|
|
31
|
+
getFileSink(version: number, attrs: CommonAttrs, xattrs: XAttrs | undefined, base: ObjSource | undefined): Promise<{
|
|
32
|
+
sinkPromise: Promise<FileByteSink>;
|
|
27
33
|
sub: Subscribe;
|
|
28
34
|
}>;
|
|
29
35
|
}
|
|
@@ -32,23 +38,30 @@ export interface FileLinkParams {
|
|
|
32
38
|
objId: string;
|
|
33
39
|
fKey: string;
|
|
34
40
|
}
|
|
35
|
-
export declare class FileNode extends NodeInFS<
|
|
41
|
+
export declare class FileNode extends NodeInFS<FilePersistance> {
|
|
42
|
+
private fileSize;
|
|
36
43
|
private constructor();
|
|
37
44
|
static makeForNew(storage: Storage, parentId: string, name: string, key: Uint8Array): Promise<FileNode>;
|
|
38
45
|
static makeForExisting(storage: Storage, parentId: string, fileName: string, objId: string, key: Uint8Array): Promise<FileNode>;
|
|
39
46
|
static makeFromLinkParams(storage: Storage, params: FileLinkParams): Promise<FileNode>;
|
|
40
47
|
private static initWithAttrs;
|
|
48
|
+
private setUpdatedState;
|
|
49
|
+
get size(): number;
|
|
41
50
|
readSrc(): Promise<{
|
|
42
51
|
src: FileByteSource;
|
|
43
52
|
version: number;
|
|
44
53
|
}>;
|
|
45
|
-
|
|
54
|
+
readBytes(start: number | undefined, end: number | undefined): Promise<{
|
|
55
|
+
bytes: Uint8Array | undefined;
|
|
56
|
+
version: number;
|
|
57
|
+
}>;
|
|
58
|
+
writeSink(truncate: boolean | undefined, currentVersion: number | undefined, changes?: XAttrsChanges): Promise<{
|
|
46
59
|
sink: FileByteSink;
|
|
47
60
|
version: number;
|
|
48
61
|
}>;
|
|
49
62
|
private startMakingSinkInsideChange;
|
|
50
63
|
private savingObjInsideChange;
|
|
51
|
-
save(bytes: Uint8Array | Uint8Array[]): Promise<number>;
|
|
64
|
+
save(bytes: Uint8Array | Uint8Array[], changes?: XAttrsChanges): Promise<number>;
|
|
52
65
|
getParamsForLink(): LinkParameters<FileLinkParams>;
|
|
53
66
|
}
|
|
54
67
|
export {};
|