core-3nweb-client-lib 0.20.9 → 0.23.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.
Files changed (67) hide show
  1. package/build/api-defs/common-caps.d.ts +6 -10
  2. package/build/api-defs/files.d.ts +8 -7
  3. package/build/core/asmail/inbox/attachments/fs.d.ts +2 -2
  4. package/build/core/asmail/inbox/attachments/fs.js +3 -2
  5. package/build/core/asmail/msg/common.d.ts +2 -2
  6. package/build/core/asmail/msg/common.js +3 -2
  7. package/build/core/asmail/msg/opener.d.ts +2 -2
  8. package/build/core/asmail/msg/opener.js +3 -2
  9. package/build/core/asmail/msg/packer.d.ts +2 -2
  10. package/build/core/asmail/msg/packer.js +7 -6
  11. package/build/core/index.d.ts +2 -2
  12. package/build/core/index.js +24 -28
  13. package/build/core/storage/index.js +2 -2
  14. package/build/core/storage/local/obj-files.js +8 -5
  15. package/build/core/storage/local/obj-status.js +4 -3
  16. package/build/core/storage/synced/obj-status.js +4 -3
  17. package/build/ipc-via-protobuf/bytes.js +1 -1
  18. package/build/ipc-via-protobuf/file.d.ts +4 -0
  19. package/build/ipc-via-protobuf/file.js +17 -15
  20. package/build/ipc-via-protobuf/fs.js +1 -1
  21. package/build/lib-client/3nstorage/xsp-fs/attrs.d.ts +28 -0
  22. package/build/lib-client/3nstorage/xsp-fs/attrs.js +337 -0
  23. package/build/lib-client/3nstorage/xsp-fs/common.d.ts +1 -1
  24. package/build/lib-client/3nstorage/xsp-fs/common.js +3 -2
  25. package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +31 -18
  26. package/build/lib-client/3nstorage/xsp-fs/file-node.js +130 -118
  27. package/build/lib-client/3nstorage/xsp-fs/file.d.ts +0 -1
  28. package/build/lib-client/3nstorage/xsp-fs/file.js +14 -49
  29. package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.d.ts +1 -1
  30. package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +95 -91
  31. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +19 -24
  32. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +133 -190
  33. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +3 -4
  34. package/build/lib-client/3nstorage/xsp-fs/fs.js +18 -21
  35. package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +13 -8
  36. package/build/lib-client/3nstorage/xsp-fs/link-node.js +46 -38
  37. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +17 -35
  38. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +34 -127
  39. package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +57 -0
  40. package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +182 -0
  41. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.d.ts +3 -0
  42. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +87 -0
  43. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.d.ts +6 -0
  44. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +1022 -0
  45. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  46. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  47. package/build/lib-client/local-files/device-fs.js +7 -3
  48. package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -2
  49. package/build/lib-client/objs-on-disk/obj-on-disk.js +8 -7
  50. package/build/lib-common/big-endian.d.ts +0 -24
  51. package/build/lib-common/big-endian.js +16 -78
  52. package/build/lib-common/exceptions/file.js +6 -2
  53. package/build/lib-common/obj-streaming/sink-utils.d.ts +0 -4
  54. package/build/lib-common/obj-streaming/sink-utils.js +4 -70
  55. package/build/lib-common/objs-on-disk/file-layout.js +2 -1
  56. package/build/lib-common/objs-on-disk/obj-file.js +2 -2
  57. package/build/lib-common/objs-on-disk/utils.js +2 -1
  58. package/build/lib-common/objs-on-disk/v1-obj-file-format.js +2 -1
  59. package/package.json +2 -2
  60. package/build/lib-client/files/file-attrs.d.ts +0 -76
  61. package/build/lib-client/files/file-attrs.js +0 -549
  62. package/build/lib-client/files/file-layout.d.ts +0 -56
  63. package/build/lib-client/files/file-layout.js +0 -456
  64. package/build/lib-client/files/file-sink.d.ts +0 -33
  65. package/build/lib-client/files/file-sink.js +0 -173
  66. package/build/lib-client/files/file-source.d.ts +0 -19
  67. package/build/lib-client/files/file-source.js +0 -115
@@ -1,549 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (C) 2020 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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.AttrsHolder = exports.makeLinkAttrs = exports.makeFolderAttrs = exports.makeFileAttrs = exports.attrType = void 0;
19
- const assert_1 = require("../../lib-common/assert");
20
- const buffer_utils_1 = require("../../lib-common/buffer-utils");
21
- const big_endian_1 = require("../../lib-common/big-endian");
22
- const json_utils_1 = require("../../lib-common/json-utils");
23
- // FS entity type values (xx_FSE)
24
- const FOLDER_JSON_V1_FSE = 0x01;
25
- // const FOLDER_BIN_V1_FSE = 0x02;
26
- const LINK_JSON_V1_FSE = 0x11;
27
- // const LINK_BIN_V1_FSE = 0x12;
28
- const FILE_V1_CONTINUOUS_FSE = 0x21;
29
- const FILE_V1_WITH_LAYOUT_FSE = 0x22;
30
- function attrType(value) {
31
- if (typeof value === 'string') {
32
- return 'named-utf8str';
33
- }
34
- else if (Buffer.isBuffer(value) || ArrayBuffer.isView(value)) {
35
- return 'named-binary';
36
- }
37
- else {
38
- return 'named-json';
39
- }
40
- }
41
- exports.attrType = attrType;
42
- function makeFileAttrs(now) {
43
- const attrs = makeAttrs('file-v1-continuous', now);
44
- attrs.size = 0;
45
- return attrs;
46
- }
47
- exports.makeFileAttrs = makeFileAttrs;
48
- function makeFolderAttrs(now) {
49
- return makeAttrs('folder-json-v1', now);
50
- }
51
- exports.makeFolderAttrs = makeFolderAttrs;
52
- function makeLinkAttrs(now) {
53
- return makeAttrs('link-json-v1', now);
54
- }
55
- exports.makeLinkAttrs = makeLinkAttrs;
56
- function makeAttrs(type, now) {
57
- return { type, ctime: now, mtime: now, ext: {} };
58
- }
59
- function readAttrs(bytes) {
60
- if (bytes.length < 1) {
61
- throw parsingException(`byte array is empty`);
62
- }
63
- const fseByte = bytes[0];
64
- bytes = bytes.slice(1);
65
- if (fseByte === FOLDER_JSON_V1_FSE) {
66
- return attrV1.readFolderAttrs(bytes, 'folder-json-v1');
67
- }
68
- else if (fseByte === LINK_JSON_V1_FSE) {
69
- return attrV1.readLinkAttrs(bytes, 'link-json-v1');
70
- }
71
- else if (fseByte === FILE_V1_CONTINUOUS_FSE) {
72
- return attrV1.readFileAttrs(bytes, 'file-v1-continuous');
73
- }
74
- else if (fseByte === FILE_V1_WITH_LAYOUT_FSE) {
75
- return attrV1.readFileAttrs(bytes, 'file-v1-w-layout');
76
- }
77
- else {
78
- throw parsingException(`Type byte ${fseByte} isn't recognized`);
79
- }
80
- }
81
- var attrV1;
82
- (function (attrV1) {
83
- function readFolderAttrs(bytes, type) {
84
- const { ctime, mtime, commAttrBytes: ofs } = readCommonAttrs(bytes);
85
- const ext = readNamedAttrs(bytes, ofs);
86
- return { type, ctime, mtime, ext };
87
- }
88
- attrV1.readFolderAttrs = readFolderAttrs;
89
- function readLinkAttrs(bytes, type) {
90
- const { ctime, mtime, commAttrBytes: ofs } = readCommonAttrs(bytes);
91
- const ext = readNamedAttrs(bytes, ofs);
92
- return { type, ctime, mtime, ext };
93
- }
94
- attrV1.readLinkAttrs = readLinkAttrs;
95
- function readFileAttrs(bytes, type) {
96
- const { ctime, mtime, commAttrBytes } = readCommonAttrs(bytes);
97
- let ofs = commAttrBytes;
98
- const sizeOrLayoutOfs = big_endian_1.uintFrom8Bytes(bytes, ofs);
99
- ofs += 8;
100
- const ext = readNamedAttrs(bytes, ofs);
101
- if (type === 'file-v1-continuous') {
102
- return { type, ctime, mtime, ext, size: sizeOrLayoutOfs };
103
- }
104
- else if (type === 'file-v1-w-layout') {
105
- return { type, ctime, mtime, ext, layoutOfs: sizeOrLayoutOfs };
106
- }
107
- else {
108
- throw new Error(`Unknown type`);
109
- }
110
- }
111
- attrV1.readFileAttrs = readFileAttrs;
112
- function readCommonAttrs(bytes) {
113
- if (bytes.length < (6 + 6)) {
114
- throw parsingException(`byte array is empty`);
115
- }
116
- const ctime = big_endian_1.uintFrom6Bytes(bytes, 0);
117
- const mtime = big_endian_1.uintFrom6Bytes(bytes, 6);
118
- return { ctime, mtime, commAttrBytes: 12 };
119
- }
120
- function writeCommonAttrs(bytes, attrs) {
121
- if (attrs.type === 'file-v1-continuous') {
122
- bytes[0] = FILE_V1_CONTINUOUS_FSE;
123
- }
124
- else if (attrs.type === 'file-v1-w-layout') {
125
- bytes[0] = FILE_V1_WITH_LAYOUT_FSE;
126
- }
127
- else if (attrs.type === 'folder-json-v1') {
128
- bytes[0] = FOLDER_JSON_V1_FSE;
129
- }
130
- else if (attrs.type === 'link-json-v1') {
131
- bytes[0] = LINK_JSON_V1_FSE;
132
- }
133
- else {
134
- throw new Error(`Attribute type is not known`);
135
- }
136
- let ofs = 1;
137
- big_endian_1.packUintTo6Bytes(attrs.ctime, bytes, ofs);
138
- ofs += 6;
139
- big_endian_1.packUintTo6Bytes(attrs.mtime, bytes, ofs);
140
- ofs += 6;
141
- if (attrs.type === 'file-v1-continuous') {
142
- assert_1.assert(Number.isInteger(attrs.size) && (attrs.size >= 0));
143
- big_endian_1.packUintTo8Bytes(attrs.size, bytes, ofs);
144
- ofs += 8;
145
- }
146
- else if (attrs.type === 'file-v1-w-layout') {
147
- assert_1.assert(Number.isInteger(attrs.layoutOfs) && (attrs.layoutOfs >= 0));
148
- big_endian_1.packUintTo8Bytes(attrs.layoutOfs, bytes, ofs);
149
- ofs += 8;
150
- }
151
- return ofs;
152
- }
153
- function readNamedAttrs(bytes, i) {
154
- const xattrs = {};
155
- while (i < bytes.length) {
156
- const r = readNamedAttr(bytes, i);
157
- if (!r) {
158
- break;
159
- }
160
- i += r.bytesRead;
161
- xattrs[r.attr.name] = r.attr;
162
- }
163
- return xattrs;
164
- }
165
- const NAMED_BINARY = 1;
166
- const NAMED_UTF8_STR = 2;
167
- const NAMED_JSON = 3;
168
- function readNamedAttr(bytes, i) {
169
- const t = parseTypeByte(bytes[i]);
170
- if (!t) {
171
- return;
172
- }
173
- let ofs = i + 1;
174
- const nameLen = readLenNum(bytes, ofs, t.nameLen);
175
- ofs += t.nameLen;
176
- const contentLen = readLenNum(bytes, ofs, t.contentLen);
177
- ofs += t.contentLen;
178
- const name = bytes.slice(ofs, ofs + nameLen).toString('utf8');
179
- ofs += nameLen;
180
- const bytesRead = ofs - i + contentLen;
181
- if ((contentLen === 0) || (bytes.length < (i + bytesRead))) {
182
- throw parsingException(`Unexpected end of byte array`);
183
- }
184
- if (t.type === NAMED_UTF8_STR) {
185
- let value;
186
- try {
187
- value = bytes.slice(ofs, ofs + contentLen).toString('utf8');
188
- }
189
- catch (err) {
190
- throw parsingException(`Error in parsing `, err);
191
- }
192
- const attr = { type: 'named-utf8str', name, value };
193
- return { attr, bytesRead };
194
- }
195
- else if (t.type === NAMED_JSON) {
196
- let value;
197
- try {
198
- value = JSON.parse(buffer_utils_1.toBuffer(bytes).slice(ofs, ofs + contentLen).toString('utf8'));
199
- }
200
- catch (err) {
201
- throw parsingException(``, err);
202
- }
203
- const attr = { type: 'named-json', name, value };
204
- return { attr, bytesRead };
205
- }
206
- else if (t.type === NAMED_BINARY) {
207
- const attr = {
208
- type: 'named-binary', name,
209
- value: bytes.slice(ofs, ofs + contentLen)
210
- };
211
- return { attr, bytesRead };
212
- }
213
- else {
214
- throw new Error(`Unknown type ${t.type} of named attribute`);
215
- }
216
- }
217
- function parseTypeByte(b) {
218
- if (b === 0) {
219
- return;
220
- }
221
- const type = ((b & 0b11100000) >> 5);
222
- const nameLen = (b & 0b00011000) >> 3;
223
- const contentLen = (b & 0b00000111);
224
- return { type, contentLen, nameLen };
225
- }
226
- function readLenNum(bytes, i, len) {
227
- switch (len) {
228
- case 1:
229
- return bytes[i];
230
- case 2:
231
- return big_endian_1.uintFrom2Bytes(bytes, i);
232
- case 3:
233
- return big_endian_1.uintFrom3Bytes(bytes, i);
234
- case 4:
235
- return big_endian_1.uintFrom4Bytes(bytes, i);
236
- case 5:
237
- return big_endian_1.uintFrom5Bytes(bytes, i);
238
- case 6:
239
- return big_endian_1.uintFrom6Bytes(bytes, i);
240
- case 7:
241
- return big_endian_1.uintFrom7Bytes(bytes, i);
242
- default:
243
- throw new Error(``);
244
- }
245
- }
246
- function packNamedStrAttr(name, value) {
247
- assert_1.assert((typeof name === 'string') && (name.length > 0) &&
248
- (typeof value === 'string') && (value.length > 0));
249
- const nameBin = Buffer.from(name, 'utf8');
250
- const valueBin = Buffer.from(value, 'utf8');
251
- return packNamedAttr(NAMED_UTF8_STR, nameBin, valueBin);
252
- }
253
- function packNamedBinaryAttr(name, value) {
254
- assert_1.assert((typeof name === 'string') && (name.length > 0) &&
255
- (value.length > 0));
256
- const nameBin = Buffer.from(name, 'utf8');
257
- return packNamedAttr(NAMED_BINARY, nameBin, value);
258
- }
259
- function packNamedJsonAttr(name, value) {
260
- assert_1.assert((typeof name === 'string') && (name.length > 0) &&
261
- (value !== undefined));
262
- const nameBin = Buffer.from(name, 'utf8');
263
- const valueBin = Buffer.from(JSON.stringify(value), 'utf8');
264
- return packNamedAttr(NAMED_JSON, nameBin, valueBin);
265
- }
266
- function packNamedAttr(type, name, value) {
267
- const nameLenLen = byteToStoreLen(name.length);
268
- if (nameLenLen > 3) {
269
- throw new Error(`Name is too long to pack`);
270
- }
271
- const contentLenLen = byteToStoreLen(value.length);
272
- const b = Buffer.allocUnsafe(1 + nameLenLen + contentLenLen + name.length + value.length);
273
- // first byte contains, left to right:
274
- // - 3 bits with type,
275
- // - 2 bits with number of bytes for name length, and
276
- // - 3 bits with number of bytes for value length
277
- b[0] = (type << 5) | (nameLenLen << 3) | contentLenLen;
278
- // bytes with length of name
279
- let i = 1;
280
- packUint(name.length, b, i, nameLenLen);
281
- // bytes with length of content
282
- i += nameLenLen;
283
- packUint(value.length, b, i, contentLenLen);
284
- // bytes with name
285
- i += contentLenLen;
286
- b.set(name, i);
287
- // bytes with content
288
- i += name.length;
289
- b.set(value, i);
290
- return b;
291
- }
292
- function byteToStoreLen(len) {
293
- if (len <= 0xff) {
294
- return 1;
295
- }
296
- else if (len <= 0xffff) {
297
- return 2;
298
- }
299
- else if (len <= 0xffffff) {
300
- return 3;
301
- }
302
- else if (len <= 0xffffffff) {
303
- return 4;
304
- }
305
- else if (len <= 0xffffffffff) {
306
- return 5;
307
- }
308
- else if (len <= 0xffffffffffff) {
309
- return 6;
310
- }
311
- else {
312
- return 7;
313
- }
314
- }
315
- function packUint(u, b, i, byteToUse) {
316
- switch (byteToUse) {
317
- case 1:
318
- b[i] = u;
319
- break;
320
- case 2:
321
- big_endian_1.packUintTo2Bytes(u, b, i);
322
- break;
323
- case 3:
324
- big_endian_1.packUintTo3Bytes(u, b, i);
325
- break;
326
- case 4:
327
- big_endian_1.packUintTo4Bytes(u, b, i);
328
- break;
329
- case 5:
330
- big_endian_1.packUintTo5Bytes(u, b, i);
331
- break;
332
- case 6:
333
- big_endian_1.packUintTo6Bytes(u, b, i);
334
- break;
335
- case 7:
336
- big_endian_1.packUintTo7Bytes(u, b, i);
337
- break;
338
- default:
339
- assert_1.assert(false);
340
- }
341
- }
342
- const FIXED_ATTRS_LEN = 1 + 6 + 6 + 8;
343
- function packAttrs(attrs) {
344
- const ext = [];
345
- for (const xattr of Object.values(attrs.ext)) {
346
- if (xattr.type === 'named-utf8str') {
347
- ext.push(packNamedStrAttr(xattr.name, xattr.value));
348
- }
349
- else if (xattr.type === 'named-json') {
350
- ext.push(packNamedJsonAttr(xattr.name, xattr.value));
351
- }
352
- else if (xattr.type === 'named-binary') {
353
- ext.push(packNamedBinaryAttr(xattr.name, xattr.value));
354
- }
355
- else {
356
- throw new Error(`Unknown type of named attribute`);
357
- }
358
- }
359
- let attrsLen = FIXED_ATTRS_LEN + ext.reduce((len, b) => len + b.length, 0);
360
- const bytes = Buffer.alloc(attrsLen, 0);
361
- writeCommonAttrs(bytes, attrs);
362
- let ofs = FIXED_ATTRS_LEN;
363
- for (const buf of ext) {
364
- bytes.set(buf, ofs);
365
- ofs += buf.length;
366
- }
367
- return bytes;
368
- }
369
- attrV1.packAttrs = packAttrs;
370
- function byteLenOf(attrs) {
371
- return packAttrs(attrs).length;
372
- }
373
- attrV1.byteLenOf = byteLenOf;
374
- })(attrV1 || (attrV1 = {}));
375
- Object.freeze(attrV1);
376
- function parsingException(msg, cause) {
377
- return {
378
- runtimeException: true,
379
- type: 'attrs-parsing',
380
- cause, msg
381
- };
382
- }
383
- function checkAttrs(json) {
384
- assert_1.assert(isFSEntityType(json.type) &&
385
- Number.isInteger(json.ctime) && Number.isInteger(json.mtime) &&
386
- !!json.ext && (typeof json.ext === 'object'));
387
- for (const n of Object.keys(json.ext)) {
388
- const v = json.ext[n];
389
- assert_1.assert(isNamedAttrType(v.type) && (typeof v.name === 'string'));
390
- if (v.type === 'named-utf8str') {
391
- assert_1.assert(typeof v.value === 'string');
392
- }
393
- else if (v.type === 'named-binary') {
394
- assert_1.assert(Buffer.isBuffer(v.value));
395
- }
396
- else {
397
- assert_1.assert((v.value !== undefined) && (typeof v.value !== 'string'));
398
- }
399
- }
400
- return json;
401
- }
402
- function isFSEntityType(type) {
403
- return ((typeof type === 'string') && ((type === 'file-v1-continuous') || (type === 'file-v1-w-layout') ||
404
- (type === 'folder-json-v1') || (type === 'link-json-v1')));
405
- }
406
- function isNamedAttrType(type) {
407
- return ((typeof type === 'string') && ((type === 'named-binary') || (type === 'named-json') ||
408
- (type === 'named-utf8str')));
409
- }
410
- class AttrsHolder {
411
- constructor(attrs, modifiable = false) {
412
- this.attrs = attrs;
413
- this.modifiable = modifiable;
414
- Object.seal(this);
415
- }
416
- modifiableCopy() {
417
- return new AttrsHolder(json_utils_1.copy(this.attrs), true);
418
- }
419
- static fromBytesReadonly(bytes) {
420
- const attrs = readAttrs(buffer_utils_1.toBuffer(bytes));
421
- return new AttrsHolder(attrs, false);
422
- }
423
- static fromJSONReadonly(attrs) {
424
- return new AttrsHolder(checkAttrs(attrs), false);
425
- }
426
- static makeReadonlyForFile(now) {
427
- const attrs = makeFileAttrs(now);
428
- return new AttrsHolder(attrs, false);
429
- }
430
- static makeReadonlyForFolder(now) {
431
- const attrs = makeFolderAttrs(now);
432
- return new AttrsHolder(attrs, false);
433
- }
434
- static makeReadonlyForLink(now) {
435
- const attrs = makeLinkAttrs(now);
436
- return new AttrsHolder(attrs, false);
437
- }
438
- toBytes() {
439
- return attrV1.packAttrs(this.attrs);
440
- }
441
- setReadonly() {
442
- this.modifiable = false;
443
- }
444
- get isReadonly() {
445
- return !this.modifiable;
446
- }
447
- throwIfReadonly() {
448
- if (!this.modifiable) {
449
- throw new Error(`Can't change readonly attributes`);
450
- }
451
- }
452
- get ctime() {
453
- return this.attrs.ctime;
454
- }
455
- set ctime(epoch) {
456
- this.throwIfReadonly();
457
- this.attrs.ctime = epoch;
458
- }
459
- get mtime() {
460
- return this.attrs.mtime;
461
- }
462
- set mtime(epoch) {
463
- this.throwIfReadonly();
464
- this.attrs.mtime = epoch;
465
- }
466
- get type() {
467
- return this.attrs.type;
468
- }
469
- get serializedLen() {
470
- return attrV1.byteLenOf(this.attrs);
471
- }
472
- getFileLayoutOfs() {
473
- if (this.attrs.type !== 'file-v1-w-layout') {
474
- return;
475
- }
476
- return this.attrs.layoutOfs;
477
- }
478
- getFileSize() {
479
- if (this.attrs.type !== 'file-v1-continuous') {
480
- return;
481
- }
482
- return this.attrs.size;
483
- }
484
- setFileLayoutOfs(ofs) {
485
- this.throwIfReadonly();
486
- assert_1.assert(Number.isInteger(ofs) && (ofs >= 0));
487
- if (this.attrs.type === 'file-v1-w-layout') {
488
- this.attrs.layoutOfs = ofs;
489
- }
490
- else if (this.attrs.type === 'file-v1-continuous') {
491
- delete this.attrs.size;
492
- this.attrs.type = 'file-v1-w-layout';
493
- this.attrs.layoutOfs = ofs;
494
- }
495
- else {
496
- throw new Error(`Layout is not supported in attributes ${this.attrs.type}`);
497
- }
498
- }
499
- setContinuousFileSize(size) {
500
- this.throwIfReadonly();
501
- assert_1.assert(Number.isInteger(size) && (size >= 0));
502
- if (this.attrs.type === 'file-v1-continuous') {
503
- this.attrs.size = size;
504
- }
505
- else if (this.attrs.type === 'file-v1-w-layout') {
506
- delete this.attrs.layoutOfs;
507
- this.attrs.type = 'file-v1-continuous';
508
- this.attrs.size = size;
509
- }
510
- else {
511
- throw new Error(`File size is not supported in attributes ${this.attrs.type}`);
512
- }
513
- }
514
- getXAttr(xaName) {
515
- const namedAttr = this.attrs.ext[xaName];
516
- if (!namedAttr) {
517
- return;
518
- }
519
- return namedAttr.value;
520
- }
521
- updateXAttrs(changes) {
522
- this.throwIfReadonly();
523
- if (Array.isArray(changes.remove)) {
524
- for (const xaName of changes.remove) {
525
- delete this.attrs.ext[xaName];
526
- }
527
- }
528
- if ((typeof changes.set === 'object') && changes.set) {
529
- for (const xaName of Object.keys(changes.set)) {
530
- const value = changes.set[xaName];
531
- if (value === undefined) {
532
- continue;
533
- }
534
- this.attrs.ext[xaName] = {
535
- name: xaName,
536
- type: attrType(value),
537
- value
538
- };
539
- }
540
- }
541
- }
542
- listXAttrs() {
543
- return Object.keys(this.attrs.ext);
544
- }
545
- }
546
- exports.AttrsHolder = AttrsHolder;
547
- Object.freeze(AttrsHolder.prototype);
548
- Object.freeze(AttrsHolder);
549
- Object.freeze(exports);
@@ -1,56 +0,0 @@
1
- import { ByteSource, Layout } from "xsp-files";
2
- declare type FileLayout = web3n.files.FileLayout;
3
- export interface ContentSection {
4
- ofsInSrc?: number;
5
- ofs: number;
6
- len: number;
7
- }
8
- export declare class ROFileLayout {
9
- private readonly sections;
10
- private readonly layoutOfs;
11
- private constructor();
12
- static orderedWithSize(size: number): ROFileLayout;
13
- static readFromSrc(src: ByteSource, layoutOfs: number): Promise<ROFileLayout>;
14
- get contentSize(): number;
15
- getSectionsIn(ofs: number, len: number | undefined): ContentSection[];
16
- makeWritableClone(): RWFileLayout;
17
- }
18
- /**
19
- * This layout expects that writes of new bytes always append raw source,
20
- * while cuts in raw source remove base bytes, but don't remove already written
21
- * new bytes, leaving them as noise.
22
- */
23
- export declare class RWFileLayout {
24
- private readonly sections;
25
- private srcBaseLen;
26
- private writePosition;
27
- constructor(sections: ContentSection[], srcBaseLen: number);
28
- static orderedWithBaseSize(size: number): RWFileLayout;
29
- static readFromSrc(src: ByteSource, layoutOfs: number): Promise<RWFileLayout>;
30
- get contentSize(): number;
31
- getSectionsIn(ofs: number, len: number | undefined): ContentSection[];
32
- getLayoutOfsInSink(): number;
33
- packIfNotTrivial(sinkLen: {
34
- size: number;
35
- isEndless: boolean;
36
- }): Uint8Array | undefined;
37
- private isTrivialLayout;
38
- toFileLayoutBasedOnSegs(segs: Layout): FileLayout;
39
- private findOffsetPosition;
40
- cutSection(ofs: number, len: number): Cut[];
41
- private shiftSectonOffsets;
42
- private turnToBaseCutsAdjustingSrcOfs;
43
- private checkAndCompactFourSections;
44
- appendEmptySection(len: number): void;
45
- insertSection(ofs: number, len: number): number;
46
- }
47
- interface Cut {
48
- ofs: number;
49
- len: number;
50
- }
51
- export interface FileLayoutException extends web3n.RuntimeException {
52
- type: 'file-layout';
53
- msg: string;
54
- }
55
- export declare function fileLayoutException(msg: string, cause?: any): FileLayoutException;
56
- export {};