@ifc-lite/cache 1.1.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/LICENSE +373 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/reader.d.ts +16 -0
- package/dist/reader.d.ts.map +1 -0
- package/dist/reader.js +102 -0
- package/dist/reader.js.map +1 -0
- package/dist/sections/entities.d.ts +28 -0
- package/dist/sections/entities.d.ts.map +1 -0
- package/dist/sections/entities.js +121 -0
- package/dist/sections/entities.js.map +1 -0
- package/dist/sections/geometry.d.ts +32 -0
- package/dist/sections/geometry.d.ts.map +1 -0
- package/dist/sections/geometry.js +125 -0
- package/dist/sections/geometry.js.map +1 -0
- package/dist/sections/header.d.ts +14 -0
- package/dist/sections/header.d.ts.map +1 -0
- package/dist/sections/header.js +95 -0
- package/dist/sections/header.js.map +1 -0
- package/dist/sections/properties.d.ts +28 -0
- package/dist/sections/properties.d.ts.map +1 -0
- package/dist/sections/properties.js +201 -0
- package/dist/sections/properties.js.map +1 -0
- package/dist/sections/quantities.d.ts +14 -0
- package/dist/sections/quantities.d.ts.map +1 -0
- package/dist/sections/quantities.js +119 -0
- package/dist/sections/quantities.js.map +1 -0
- package/dist/sections/relationships.d.ts +21 -0
- package/dist/sections/relationships.d.ts.map +1 -0
- package/dist/sections/relationships.js +134 -0
- package/dist/sections/relationships.js.map +1 -0
- package/dist/sections/strings.d.ts +18 -0
- package/dist/sections/strings.d.ts.map +1 -0
- package/dist/sections/strings.js +59 -0
- package/dist/sections/strings.js.map +1 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +45 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/buffer-utils.d.ts +65 -0
- package/dist/utils/buffer-utils.d.ts.map +1 -0
- package/dist/utils/buffer-utils.js +204 -0
- package/dist/utils/buffer-utils.js.map +1 -0
- package/dist/utils/hash.d.ts +12 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +99 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/writer.d.ts +24 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +125 -0
- package/dist/writer.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
/**
|
|
5
|
+
* Buffer utilities for reading/writing binary data
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Writer for building binary buffers
|
|
9
|
+
*/
|
|
10
|
+
export class BufferWriter {
|
|
11
|
+
chunks = [];
|
|
12
|
+
currentChunk;
|
|
13
|
+
view;
|
|
14
|
+
offset = 0;
|
|
15
|
+
totalSize = 0;
|
|
16
|
+
constructor(initialSize = 1024 * 1024) {
|
|
17
|
+
this.currentChunk = new Uint8Array(initialSize);
|
|
18
|
+
this.view = new DataView(this.currentChunk.buffer);
|
|
19
|
+
}
|
|
20
|
+
ensureCapacity(bytes) {
|
|
21
|
+
if (this.offset + bytes > this.currentChunk.length) {
|
|
22
|
+
// Save current chunk and create new one
|
|
23
|
+
this.chunks.push(this.currentChunk.subarray(0, this.offset));
|
|
24
|
+
this.totalSize += this.offset;
|
|
25
|
+
const newSize = Math.max(bytes, this.currentChunk.length);
|
|
26
|
+
this.currentChunk = new Uint8Array(newSize);
|
|
27
|
+
this.view = new DataView(this.currentChunk.buffer);
|
|
28
|
+
this.offset = 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
writeUint8(value) {
|
|
32
|
+
this.ensureCapacity(1);
|
|
33
|
+
this.currentChunk[this.offset++] = value;
|
|
34
|
+
}
|
|
35
|
+
writeUint16(value) {
|
|
36
|
+
this.ensureCapacity(2);
|
|
37
|
+
this.view.setUint16(this.offset, value, true);
|
|
38
|
+
this.offset += 2;
|
|
39
|
+
}
|
|
40
|
+
writeUint32(value) {
|
|
41
|
+
this.ensureCapacity(4);
|
|
42
|
+
this.view.setUint32(this.offset, value, true);
|
|
43
|
+
this.offset += 4;
|
|
44
|
+
}
|
|
45
|
+
writeInt32(value) {
|
|
46
|
+
this.ensureCapacity(4);
|
|
47
|
+
this.view.setInt32(this.offset, value, true);
|
|
48
|
+
this.offset += 4;
|
|
49
|
+
}
|
|
50
|
+
writeBigUint64(value) {
|
|
51
|
+
this.ensureCapacity(8);
|
|
52
|
+
this.view.setBigUint64(this.offset, value, true);
|
|
53
|
+
this.offset += 8;
|
|
54
|
+
}
|
|
55
|
+
writeFloat32(value) {
|
|
56
|
+
this.ensureCapacity(4);
|
|
57
|
+
this.view.setFloat32(this.offset, value, true);
|
|
58
|
+
this.offset += 4;
|
|
59
|
+
}
|
|
60
|
+
writeFloat64(value) {
|
|
61
|
+
this.ensureCapacity(8);
|
|
62
|
+
this.view.setFloat64(this.offset, value, true);
|
|
63
|
+
this.offset += 8;
|
|
64
|
+
}
|
|
65
|
+
writeBytes(data) {
|
|
66
|
+
this.ensureCapacity(data.length);
|
|
67
|
+
this.currentChunk.set(data, this.offset);
|
|
68
|
+
this.offset += data.length;
|
|
69
|
+
}
|
|
70
|
+
writeTypedArray(arr) {
|
|
71
|
+
const bytes = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
72
|
+
this.writeBytes(bytes);
|
|
73
|
+
}
|
|
74
|
+
writeString(str) {
|
|
75
|
+
const encoder = new TextEncoder();
|
|
76
|
+
const bytes = encoder.encode(str);
|
|
77
|
+
this.writeUint32(bytes.length);
|
|
78
|
+
this.writeBytes(bytes);
|
|
79
|
+
}
|
|
80
|
+
/** Pad to alignment boundary */
|
|
81
|
+
align(boundary) {
|
|
82
|
+
const currentPos = this.totalSize + this.offset;
|
|
83
|
+
const padding = (boundary - (currentPos % boundary)) % boundary;
|
|
84
|
+
for (let i = 0; i < padding; i++) {
|
|
85
|
+
this.writeUint8(0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Get current position */
|
|
89
|
+
get position() {
|
|
90
|
+
return this.totalSize + this.offset;
|
|
91
|
+
}
|
|
92
|
+
/** Build final buffer */
|
|
93
|
+
build() {
|
|
94
|
+
// Include current chunk
|
|
95
|
+
this.chunks.push(this.currentChunk.subarray(0, this.offset));
|
|
96
|
+
this.totalSize += this.offset;
|
|
97
|
+
// Concatenate all chunks
|
|
98
|
+
const result = new Uint8Array(this.totalSize);
|
|
99
|
+
let pos = 0;
|
|
100
|
+
for (const chunk of this.chunks) {
|
|
101
|
+
result.set(chunk, pos);
|
|
102
|
+
pos += chunk.length;
|
|
103
|
+
}
|
|
104
|
+
return result.buffer;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reader for parsing binary buffers
|
|
109
|
+
*/
|
|
110
|
+
export class BufferReader {
|
|
111
|
+
view;
|
|
112
|
+
bytes;
|
|
113
|
+
offset = 0;
|
|
114
|
+
constructor(buffer) {
|
|
115
|
+
this.view = new DataView(buffer);
|
|
116
|
+
this.bytes = new Uint8Array(buffer);
|
|
117
|
+
}
|
|
118
|
+
get position() {
|
|
119
|
+
return this.offset;
|
|
120
|
+
}
|
|
121
|
+
set position(pos) {
|
|
122
|
+
this.offset = pos;
|
|
123
|
+
}
|
|
124
|
+
get remaining() {
|
|
125
|
+
return this.bytes.length - this.offset;
|
|
126
|
+
}
|
|
127
|
+
readUint8() {
|
|
128
|
+
return this.bytes[this.offset++];
|
|
129
|
+
}
|
|
130
|
+
readUint16() {
|
|
131
|
+
const value = this.view.getUint16(this.offset, true);
|
|
132
|
+
this.offset += 2;
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
readUint32() {
|
|
136
|
+
const value = this.view.getUint32(this.offset, true);
|
|
137
|
+
this.offset += 4;
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
readInt32() {
|
|
141
|
+
const value = this.view.getInt32(this.offset, true);
|
|
142
|
+
this.offset += 4;
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
readBigUint64() {
|
|
146
|
+
const value = this.view.getBigUint64(this.offset, true);
|
|
147
|
+
this.offset += 8;
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
readFloat32() {
|
|
151
|
+
const value = this.view.getFloat32(this.offset, true);
|
|
152
|
+
this.offset += 4;
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
readFloat64() {
|
|
156
|
+
const value = this.view.getFloat64(this.offset, true);
|
|
157
|
+
this.offset += 8;
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
readBytes(length) {
|
|
161
|
+
const slice = this.bytes.slice(this.offset, this.offset + length);
|
|
162
|
+
this.offset += length;
|
|
163
|
+
return slice;
|
|
164
|
+
}
|
|
165
|
+
readUint8Array(length) {
|
|
166
|
+
return this.readBytes(length);
|
|
167
|
+
}
|
|
168
|
+
readUint16Array(length) {
|
|
169
|
+
const bytes = this.readBytes(length * 2);
|
|
170
|
+
return new Uint16Array(bytes.buffer, bytes.byteOffset, length);
|
|
171
|
+
}
|
|
172
|
+
readUint32Array(length) {
|
|
173
|
+
const bytes = this.readBytes(length * 4);
|
|
174
|
+
return new Uint32Array(bytes.buffer, bytes.byteOffset, length);
|
|
175
|
+
}
|
|
176
|
+
readInt32Array(length) {
|
|
177
|
+
const bytes = this.readBytes(length * 4);
|
|
178
|
+
return new Int32Array(bytes.buffer, bytes.byteOffset, length);
|
|
179
|
+
}
|
|
180
|
+
readFloat32Array(length) {
|
|
181
|
+
const bytes = this.readBytes(length * 4);
|
|
182
|
+
return new Float32Array(bytes.buffer, bytes.byteOffset, length);
|
|
183
|
+
}
|
|
184
|
+
readFloat64Array(length) {
|
|
185
|
+
const bytes = this.readBytes(length * 8);
|
|
186
|
+
return new Float64Array(bytes.buffer, bytes.byteOffset, length);
|
|
187
|
+
}
|
|
188
|
+
readString() {
|
|
189
|
+
const length = this.readUint32();
|
|
190
|
+
const bytes = this.readBytes(length);
|
|
191
|
+
const decoder = new TextDecoder();
|
|
192
|
+
return decoder.decode(bytes);
|
|
193
|
+
}
|
|
194
|
+
/** Skip to alignment boundary */
|
|
195
|
+
align(boundary) {
|
|
196
|
+
const padding = (boundary - (this.offset % boundary)) % boundary;
|
|
197
|
+
this.offset += padding;
|
|
198
|
+
}
|
|
199
|
+
/** Skip bytes */
|
|
200
|
+
skip(bytes) {
|
|
201
|
+
this.offset += bytes;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=buffer-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-utils.js","sourceRoot":"","sources":["../../src/utils/buffer-utils.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,MAAM,GAAiB,EAAE,CAAC;IAC1B,YAAY,CAAa;IACzB,IAAI,CAAW;IACf,MAAM,GAAW,CAAC,CAAC;IACnB,SAAS,GAAW,CAAC,CAAC;IAE9B,YAAY,cAAsB,IAAI,GAAG,IAAI;QAC3C,IAAI,CAAC,YAAY,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IAEO,cAAc,CAAC,KAAa;QAClC,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;YACnD,wCAAwC;YACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,IAA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
+
* @param seed - Optional seed value (default: 0)
|
|
5
|
+
* @returns 64-bit hash as bigint
|
|
6
|
+
*/
|
|
7
|
+
export declare function xxhash64(data: ArrayBuffer | Uint8Array, seed?: bigint): bigint;
|
|
8
|
+
/**
|
|
9
|
+
* Compute xxHash64 and return as hex string
|
|
10
|
+
*/
|
|
11
|
+
export declare function xxhash64Hex(data: ArrayBuffer | Uint8Array, seed?: bigint): string;
|
|
12
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AA0CA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,EAAE,IAAI,GAAE,MAAW,GAAG,MAAM,CA0DlF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,EAAE,IAAI,GAAE,MAAW,GAAG,MAAM,CAErF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
/**
|
|
5
|
+
* xxHash64 implementation for source file validation
|
|
6
|
+
* Based on the xxHash algorithm by Yann Collet
|
|
7
|
+
*/
|
|
8
|
+
const PRIME64_1 = 0x9e3779b185ebca87n;
|
|
9
|
+
const PRIME64_2 = 0xc2b2ae3d27d4eb4fn;
|
|
10
|
+
const PRIME64_3 = 0x165667b19e3779f9n;
|
|
11
|
+
const PRIME64_4 = 0x85ebca77c2b2ae63n;
|
|
12
|
+
const PRIME64_5 = 0x27d4eb2f165667c5n;
|
|
13
|
+
function rotl64(x, r) {
|
|
14
|
+
return ((x << BigInt(r)) | (x >> BigInt(64 - r))) & 0xffffffffffffffffn;
|
|
15
|
+
}
|
|
16
|
+
function round64(acc, input) {
|
|
17
|
+
acc = (acc + input * PRIME64_2) & 0xffffffffffffffffn;
|
|
18
|
+
acc = rotl64(acc, 31);
|
|
19
|
+
acc = (acc * PRIME64_1) & 0xffffffffffffffffn;
|
|
20
|
+
return acc;
|
|
21
|
+
}
|
|
22
|
+
function mergeRound64(acc, val) {
|
|
23
|
+
val = round64(0n, val);
|
|
24
|
+
acc = (acc ^ val) & 0xffffffffffffffffn;
|
|
25
|
+
acc = (acc * PRIME64_1 + PRIME64_4) & 0xffffffffffffffffn;
|
|
26
|
+
return acc;
|
|
27
|
+
}
|
|
28
|
+
function avalanche64(h) {
|
|
29
|
+
h = (h ^ (h >> 33n)) & 0xffffffffffffffffn;
|
|
30
|
+
h = (h * PRIME64_2) & 0xffffffffffffffffn;
|
|
31
|
+
h = (h ^ (h >> 29n)) & 0xffffffffffffffffn;
|
|
32
|
+
h = (h * PRIME64_3) & 0xffffffffffffffffn;
|
|
33
|
+
h = (h ^ (h >> 32n)) & 0xffffffffffffffffn;
|
|
34
|
+
return h;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Compute xxHash64 of a buffer
|
|
38
|
+
* @param data - Input data as ArrayBuffer or Uint8Array
|
|
39
|
+
* @param seed - Optional seed value (default: 0)
|
|
40
|
+
* @returns 64-bit hash as bigint
|
|
41
|
+
*/
|
|
42
|
+
export function xxhash64(data, seed = 0n) {
|
|
43
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
44
|
+
const len = bytes.length;
|
|
45
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
46
|
+
let h64;
|
|
47
|
+
let offset = 0;
|
|
48
|
+
if (len >= 32) {
|
|
49
|
+
let v1 = (seed + PRIME64_1 + PRIME64_2) & 0xffffffffffffffffn;
|
|
50
|
+
let v2 = (seed + PRIME64_2) & 0xffffffffffffffffn;
|
|
51
|
+
let v3 = seed;
|
|
52
|
+
let v4 = (seed - PRIME64_1) & 0xffffffffffffffffn;
|
|
53
|
+
const limit = len - 32;
|
|
54
|
+
while (offset <= limit) {
|
|
55
|
+
v1 = round64(v1, view.getBigUint64(offset, true));
|
|
56
|
+
v2 = round64(v2, view.getBigUint64(offset + 8, true));
|
|
57
|
+
v3 = round64(v3, view.getBigUint64(offset + 16, true));
|
|
58
|
+
v4 = round64(v4, view.getBigUint64(offset + 24, true));
|
|
59
|
+
offset += 32;
|
|
60
|
+
}
|
|
61
|
+
h64 = rotl64(v1, 1) + rotl64(v2, 7) + rotl64(v3, 12) + rotl64(v4, 18);
|
|
62
|
+
h64 = h64 & 0xffffffffffffffffn;
|
|
63
|
+
h64 = mergeRound64(h64, v1);
|
|
64
|
+
h64 = mergeRound64(h64, v2);
|
|
65
|
+
h64 = mergeRound64(h64, v3);
|
|
66
|
+
h64 = mergeRound64(h64, v4);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
h64 = (seed + PRIME64_5) & 0xffffffffffffffffn;
|
|
70
|
+
}
|
|
71
|
+
h64 = (h64 + BigInt(len)) & 0xffffffffffffffffn;
|
|
72
|
+
// Process remaining 8-byte chunks
|
|
73
|
+
while (offset + 8 <= len) {
|
|
74
|
+
const k1 = round64(0n, view.getBigUint64(offset, true));
|
|
75
|
+
h64 = (h64 ^ k1) & 0xffffffffffffffffn;
|
|
76
|
+
h64 = (rotl64(h64, 27) * PRIME64_1 + PRIME64_4) & 0xffffffffffffffffn;
|
|
77
|
+
offset += 8;
|
|
78
|
+
}
|
|
79
|
+
// Process remaining 4-byte chunk
|
|
80
|
+
if (offset + 4 <= len) {
|
|
81
|
+
h64 = (h64 ^ (BigInt(view.getUint32(offset, true)) * PRIME64_1)) & 0xffffffffffffffffn;
|
|
82
|
+
h64 = (rotl64(h64, 23) * PRIME64_2 + PRIME64_3) & 0xffffffffffffffffn;
|
|
83
|
+
offset += 4;
|
|
84
|
+
}
|
|
85
|
+
// Process remaining bytes
|
|
86
|
+
while (offset < len) {
|
|
87
|
+
h64 = (h64 ^ (BigInt(bytes[offset]) * PRIME64_5)) & 0xffffffffffffffffn;
|
|
88
|
+
h64 = (rotl64(h64, 11) * PRIME64_1) & 0xffffffffffffffffn;
|
|
89
|
+
offset++;
|
|
90
|
+
}
|
|
91
|
+
return avalanche64(h64);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Compute xxHash64 and return as hex string
|
|
95
|
+
*/
|
|
96
|
+
export function xxhash64Hex(data, seed = 0n) {
|
|
97
|
+
return xxhash64(data, seed).toString(16).padStart(16, '0');
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;GAGG;AAEH,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;AAC1E,CAAC;AAED,SAAS,OAAO,CAAC,GAAW,EAAE,KAAa;IACzC,GAAG,GAAG,CAAC,GAAG,GAAG,KAAK,GAAG,SAAS,CAAC,GAAG,mBAAmB,CAAC;IACtD,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACtB,GAAG,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,mBAAmB,CAAC;IAC9C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CAA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GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,GAAG,mBAAmB,CAAC;QAC1D,MAAM,EAAE,CAAC;IACX,CAAC;IAED,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAA8B,EAAE,OAAe,EAAE;IAC3E,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC"}
|
package/dist/writer.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BinaryCacheWriter - writes .ifc-lite binary cache files
|
|
3
|
+
*/
|
|
4
|
+
import type { MeshData, CoordinateInfo } from '@ifc-lite/geometry';
|
|
5
|
+
import { type CacheWriteOptions, type IfcDataStore } from './types.js';
|
|
6
|
+
export interface GeometryData {
|
|
7
|
+
meshes: MeshData[];
|
|
8
|
+
totalVertices: number;
|
|
9
|
+
totalTriangles: number;
|
|
10
|
+
coordinateInfo: CoordinateInfo;
|
|
11
|
+
}
|
|
12
|
+
export declare class BinaryCacheWriter {
|
|
13
|
+
/**
|
|
14
|
+
* Write a complete cache file
|
|
15
|
+
* @param dataStore - The parsed IFC data store
|
|
16
|
+
* @param geometry - Optional geometry data
|
|
17
|
+
* @param sourceBuffer - Original IFC buffer (for hash)
|
|
18
|
+
* @param options - Write options
|
|
19
|
+
* @returns ArrayBuffer containing the binary cache
|
|
20
|
+
*/
|
|
21
|
+
write(dataStore: IfcDataStore, geometry: GeometryData | undefined, sourceBuffer: ArrayBuffer, options?: CacheWriteOptions): Promise<ArrayBuffer>;
|
|
22
|
+
private writeSection;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EASL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAWpB,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,qBAAa,iBAAiB;IAC5B;;;;;;;OAOG;IACG,KAAK,CACT,SAAS,EAAE,YAAY,EACvB,QAAQ,EAAE,YAAY,GAAG,SAAS,EAClC,YAAY,EAAE,WAAW,EACzB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,WAAW,CAAC;IA6HvB,OAAO,CAAC,YAAY;CAGrB"}
|
package/dist/writer.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
import { FORMAT_VERSION, HEADER_SIZE, SECTION_ENTRY_SIZE, SectionType, HeaderFlags, SectionFlags, } from './types.js';
|
|
5
|
+
import { BufferWriter } from './utils/buffer-utils.js';
|
|
6
|
+
import { xxhash64 } from './utils/hash.js';
|
|
7
|
+
import { writeHeader } from './sections/header.js';
|
|
8
|
+
import { writeStrings } from './sections/strings.js';
|
|
9
|
+
import { writeEntities } from './sections/entities.js';
|
|
10
|
+
import { writeProperties } from './sections/properties.js';
|
|
11
|
+
import { writeQuantities } from './sections/quantities.js';
|
|
12
|
+
import { writeRelationships } from './sections/relationships.js';
|
|
13
|
+
import { writeGeometry } from './sections/geometry.js';
|
|
14
|
+
export class BinaryCacheWriter {
|
|
15
|
+
/**
|
|
16
|
+
* Write a complete cache file
|
|
17
|
+
* @param dataStore - The parsed IFC data store
|
|
18
|
+
* @param geometry - Optional geometry data
|
|
19
|
+
* @param sourceBuffer - Original IFC buffer (for hash)
|
|
20
|
+
* @param options - Write options
|
|
21
|
+
* @returns ArrayBuffer containing the binary cache
|
|
22
|
+
*/
|
|
23
|
+
async write(dataStore, geometry, sourceBuffer, options = {}) {
|
|
24
|
+
const { includeGeometry = true, includeSpatialHierarchy = true, } = options;
|
|
25
|
+
// Compute source hash
|
|
26
|
+
const sourceHash = xxhash64(sourceBuffer);
|
|
27
|
+
// Build sections
|
|
28
|
+
const sectionBuffers = [];
|
|
29
|
+
// Strings section (always required)
|
|
30
|
+
const stringsBuffer = this.writeSection(() => {
|
|
31
|
+
const writer = new BufferWriter();
|
|
32
|
+
writeStrings(writer, dataStore.strings);
|
|
33
|
+
return writer.build();
|
|
34
|
+
});
|
|
35
|
+
sectionBuffers.push({ type: SectionType.Strings, buffer: stringsBuffer });
|
|
36
|
+
// Entities section
|
|
37
|
+
const entitiesBuffer = this.writeSection(() => {
|
|
38
|
+
const writer = new BufferWriter();
|
|
39
|
+
writeEntities(writer, dataStore.entities);
|
|
40
|
+
return writer.build();
|
|
41
|
+
});
|
|
42
|
+
sectionBuffers.push({ type: SectionType.Entities, buffer: entitiesBuffer });
|
|
43
|
+
// Properties section
|
|
44
|
+
const propertiesBuffer = this.writeSection(() => {
|
|
45
|
+
const writer = new BufferWriter();
|
|
46
|
+
writeProperties(writer, dataStore.properties);
|
|
47
|
+
return writer.build();
|
|
48
|
+
});
|
|
49
|
+
sectionBuffers.push({ type: SectionType.Properties, buffer: propertiesBuffer });
|
|
50
|
+
// Quantities section
|
|
51
|
+
const quantitiesBuffer = this.writeSection(() => {
|
|
52
|
+
const writer = new BufferWriter();
|
|
53
|
+
writeQuantities(writer, dataStore.quantities);
|
|
54
|
+
return writer.build();
|
|
55
|
+
});
|
|
56
|
+
sectionBuffers.push({ type: SectionType.Quantities, buffer: quantitiesBuffer });
|
|
57
|
+
// Relationships section
|
|
58
|
+
const relationshipsBuffer = this.writeSection(() => {
|
|
59
|
+
const writer = new BufferWriter();
|
|
60
|
+
writeRelationships(writer, dataStore.relationships);
|
|
61
|
+
return writer.build();
|
|
62
|
+
});
|
|
63
|
+
sectionBuffers.push({ type: SectionType.Relationships, buffer: relationshipsBuffer });
|
|
64
|
+
// Geometry section (optional)
|
|
65
|
+
let totalVertices = 0;
|
|
66
|
+
let totalTriangles = 0;
|
|
67
|
+
if (includeGeometry && geometry) {
|
|
68
|
+
const geometryBuffer = this.writeSection(() => {
|
|
69
|
+
const writer = new BufferWriter();
|
|
70
|
+
writeGeometry(writer, geometry.meshes, geometry.totalVertices, geometry.totalTriangles, geometry.coordinateInfo);
|
|
71
|
+
return writer.build();
|
|
72
|
+
});
|
|
73
|
+
sectionBuffers.push({ type: SectionType.Geometry, buffer: geometryBuffer });
|
|
74
|
+
totalVertices = geometry.totalVertices;
|
|
75
|
+
totalTriangles = geometry.totalTriangles;
|
|
76
|
+
}
|
|
77
|
+
// Calculate offsets
|
|
78
|
+
const sectionTableSize = sectionBuffers.length * SECTION_ENTRY_SIZE;
|
|
79
|
+
let currentOffset = HEADER_SIZE + sectionTableSize;
|
|
80
|
+
const sections = sectionBuffers.map(({ type, buffer }) => {
|
|
81
|
+
const entry = {
|
|
82
|
+
type,
|
|
83
|
+
flags: SectionFlags.None,
|
|
84
|
+
offset: currentOffset,
|
|
85
|
+
size: buffer.byteLength,
|
|
86
|
+
compressedSize: 0,
|
|
87
|
+
};
|
|
88
|
+
currentOffset += buffer.byteLength;
|
|
89
|
+
return entry;
|
|
90
|
+
});
|
|
91
|
+
// Build header flags
|
|
92
|
+
let headerFlags = HeaderFlags.None;
|
|
93
|
+
if (includeGeometry && geometry) {
|
|
94
|
+
headerFlags |= HeaderFlags.HasGeometry;
|
|
95
|
+
}
|
|
96
|
+
if (includeSpatialHierarchy && dataStore.spatialHierarchy) {
|
|
97
|
+
headerFlags |= HeaderFlags.HasSpatial;
|
|
98
|
+
}
|
|
99
|
+
const header = {
|
|
100
|
+
magic: 0x4C434649,
|
|
101
|
+
version: FORMAT_VERSION,
|
|
102
|
+
flags: headerFlags,
|
|
103
|
+
sourceHash,
|
|
104
|
+
schema: dataStore.schema,
|
|
105
|
+
entityCount: dataStore.entityCount,
|
|
106
|
+
totalVertices,
|
|
107
|
+
totalTriangles,
|
|
108
|
+
sectionCount: sections.length,
|
|
109
|
+
};
|
|
110
|
+
// Assemble final buffer
|
|
111
|
+
const totalSize = currentOffset;
|
|
112
|
+
const finalWriter = new BufferWriter(totalSize);
|
|
113
|
+
// Write header and section table
|
|
114
|
+
writeHeader(finalWriter, header, sections);
|
|
115
|
+
// Write section data
|
|
116
|
+
for (const { buffer } of sectionBuffers) {
|
|
117
|
+
finalWriter.writeBytes(new Uint8Array(buffer));
|
|
118
|
+
}
|
|
119
|
+
return finalWriter.build();
|
|
120
|
+
}
|
|
121
|
+
writeSection(fn) {
|
|
122
|
+
return fn();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAO/D,OAAO,EACL,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,YAAY,GAKb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO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UAAU,CAAC;QACxC,CAAC;QAED,MAAM,MAAM,GAAgB;YAC1B,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,cAAc;YACvB,KAAK,EAAE,WAAW;YAClB,UAAU;YACV,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,WAAW,EAAE,SAAS,CAAC,WAAW;YAClC,aAAa;YACb,cAAc;YACd,YAAY,EAAE,QAAQ,CAAC,MAAM;SAC9B,CAAC;QAEF,wBAAwB;QACxB,MAAM,SAAS,GAAG,aAAa,CAAC;QAChC,MAAM,WAAW,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;QAEhD,iCAAiC;QACjC,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;QAE3C,qBAAqB;QACrB,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,cAAc,EAAE,CAAC;YACxC,WAAW,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,WAAW,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAEO,YAAY,CAAC,EAAqB;QACxC,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ifc-lite/cache",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Binary cache format for IFC-Lite - fast model loading",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@ifc-lite/data": "1.1.0",
|
|
16
|
+
"@ifc-lite/geometry": "1.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"typescript": "^5.3.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "MPL-2.0",
|
|
22
|
+
"author": "Louis True",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/louistrue/ifc-lite.git",
|
|
26
|
+
"directory": "packages/cache"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://louistrue.github.io/ifc-lite/",
|
|
29
|
+
"bugs": "https://github.com/louistrue/ifc-lite/issues",
|
|
30
|
+
"keywords": [
|
|
31
|
+
"ifc",
|
|
32
|
+
"bim",
|
|
33
|
+
"cache",
|
|
34
|
+
"binary",
|
|
35
|
+
"aec"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"dev": "tsc --watch",
|
|
47
|
+
"test": "tsx --test src/**/*.test.ts"
|
|
48
|
+
}
|
|
49
|
+
}
|