archive-codec 1.2.0 → 1.4.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/README.md +71 -11
- package/dist/cfb/write.cjs +297 -0
- package/dist/cfb/write.d.cts +11 -0
- package/dist/cfb/write.d.ts +11 -0
- package/dist/cfb/write.js +295 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +6 -1
- package/dist/oleps/layout-metadata.cjs +30 -0
- package/dist/oleps/layout-metadata.d.cts +9 -0
- package/dist/oleps/layout-metadata.d.ts +9 -0
- package/dist/oleps/layout-metadata.js +27 -0
- package/dist/oleps/read.cjs +132 -0
- package/dist/oleps/read.d.cts +8 -0
- package/dist/oleps/read.d.ts +8 -0
- package/dist/oleps/read.js +130 -0
- package/dist/oleps/summary-information.cjs +94 -0
- package/dist/oleps/summary-information.d.cts +16 -0
- package/dist/oleps/summary-information.d.ts +16 -0
- package/dist/oleps/summary-information.js +91 -0
- package/dist/oleps/wire.cjs +70 -0
- package/dist/oleps/wire.d.cts +45 -0
- package/dist/oleps/wire.d.ts +45 -0
- package/dist/oleps/wire.js +51 -0
- package/dist/oleps/write.cjs +103 -0
- package/dist/oleps/write.d.cts +8 -0
- package/dist/oleps/write.d.ts +8 -0
- package/dist/oleps/write.js +101 -0
- package/package.json +3 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PropertySet } from "./wire.js";
|
|
2
|
+
//#region src/oleps/write.d.ts
|
|
3
|
+
declare class PropertySetWriteError extends Error {
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
declare function writePropertySetStream(propertySet: PropertySet): Uint8Array<ArrayBuffer>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { PropertySetWriteError, writePropertySetStream };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { BYTE_ORDER_MARK, GUID_NULL, dateToFiletime, writeGuid } from "./wire.js";
|
|
2
|
+
//#region src/oleps/write.ts
|
|
3
|
+
var PropertySetWriteError = class extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "PropertySetWriteError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function encodeUnicodeStringValue(value) {
|
|
10
|
+
const characterBytes = new Uint8Array((value.length + 1) * 2);
|
|
11
|
+
const charView = new DataView(characterBytes.buffer);
|
|
12
|
+
for (let i = 0; i < value.length; i++) charView.setUint16(i * 2, value.charCodeAt(i), true);
|
|
13
|
+
charView.setUint16(value.length * 2, 0, true);
|
|
14
|
+
return characterBytes;
|
|
15
|
+
}
|
|
16
|
+
function padTo4(length) {
|
|
17
|
+
return Math.ceil(length / 4) * 4;
|
|
18
|
+
}
|
|
19
|
+
function encodeTypedPropertyValue(value) {
|
|
20
|
+
switch (value.type) {
|
|
21
|
+
case "VT_I2": {
|
|
22
|
+
const bytes = /* @__PURE__ */ new Uint8Array(8);
|
|
23
|
+
const view = new DataView(bytes.buffer);
|
|
24
|
+
view.setUint16(0, 2, true);
|
|
25
|
+
view.setUint16(2, 0, true);
|
|
26
|
+
view.setInt16(4, value.value, true);
|
|
27
|
+
view.setUint16(6, 0, true);
|
|
28
|
+
return bytes;
|
|
29
|
+
}
|
|
30
|
+
case "VT_I4": {
|
|
31
|
+
const bytes = /* @__PURE__ */ new Uint8Array(8);
|
|
32
|
+
const view = new DataView(bytes.buffer);
|
|
33
|
+
view.setUint16(0, 3, true);
|
|
34
|
+
view.setUint16(2, 0, true);
|
|
35
|
+
view.setInt32(4, value.value, true);
|
|
36
|
+
return bytes;
|
|
37
|
+
}
|
|
38
|
+
case "VT_FILETIME": {
|
|
39
|
+
const { low, high } = dateToFiletime(value.value);
|
|
40
|
+
const bytes = /* @__PURE__ */ new Uint8Array(12);
|
|
41
|
+
const view = new DataView(bytes.buffer);
|
|
42
|
+
view.setUint16(0, 64, true);
|
|
43
|
+
view.setUint16(2, 0, true);
|
|
44
|
+
view.setUint32(4, low, true);
|
|
45
|
+
view.setUint32(8, high, true);
|
|
46
|
+
return bytes;
|
|
47
|
+
}
|
|
48
|
+
case "VT_LPWSTR": {
|
|
49
|
+
const characters = encodeUnicodeStringValue(value.value);
|
|
50
|
+
const paddedLength = padTo4(characters.length);
|
|
51
|
+
const bytes = new Uint8Array(8 + paddedLength);
|
|
52
|
+
const view = new DataView(bytes.buffer);
|
|
53
|
+
view.setUint16(0, 31, true);
|
|
54
|
+
view.setUint16(2, 0, true);
|
|
55
|
+
view.setUint32(4, characters.length / 2, true);
|
|
56
|
+
bytes.set(characters, 8);
|
|
57
|
+
return bytes;
|
|
58
|
+
}
|
|
59
|
+
case "VT_LPSTR": throw new PropertySetWriteError("writePropertySetStream cannot write a VT_LPSTR property: this writer emits Unicode (VT_LPWSTR) strings only, since encoding to an arbitrary ANSI codepage is out of scope -- see the package README's OLEPS scope note");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function writePropertySetStream(propertySet) {
|
|
63
|
+
const entries = [...propertySet.properties.entries()].sort(([a], [b]) => a - b);
|
|
64
|
+
const dictionaryBytes = new Uint8Array(entries.length * 8);
|
|
65
|
+
const dictionaryView = new DataView(dictionaryBytes.buffer);
|
|
66
|
+
const valueChunks = [];
|
|
67
|
+
let valueOffset = 8 + dictionaryBytes.length;
|
|
68
|
+
let index = 0;
|
|
69
|
+
for (const [pid, value] of entries) {
|
|
70
|
+
const encoded = encodeTypedPropertyValue(value);
|
|
71
|
+
dictionaryView.setUint32(index * 8, pid, true);
|
|
72
|
+
dictionaryView.setUint32(index * 8 + 4, valueOffset, true);
|
|
73
|
+
valueChunks.push(encoded);
|
|
74
|
+
valueOffset += encoded.length;
|
|
75
|
+
index += 1;
|
|
76
|
+
}
|
|
77
|
+
const propertySetSize = valueOffset;
|
|
78
|
+
const propertySetBytes = new Uint8Array(propertySetSize);
|
|
79
|
+
const propertySetView = new DataView(propertySetBytes.buffer);
|
|
80
|
+
propertySetView.setUint32(0, propertySetSize, true);
|
|
81
|
+
propertySetView.setUint32(4, entries.length, true);
|
|
82
|
+
propertySetBytes.set(dictionaryBytes, 8);
|
|
83
|
+
let cursor = 8 + dictionaryBytes.length;
|
|
84
|
+
for (const chunk of valueChunks) {
|
|
85
|
+
propertySetBytes.set(chunk, cursor);
|
|
86
|
+
cursor += chunk.length;
|
|
87
|
+
}
|
|
88
|
+
const streamBytes = new Uint8Array(48 + propertySetBytes.length);
|
|
89
|
+
const view = new DataView(streamBytes.buffer);
|
|
90
|
+
view.setUint16(0, BYTE_ORDER_MARK, true);
|
|
91
|
+
view.setUint16(2, 0, true);
|
|
92
|
+
view.setUint32(4, 0, true);
|
|
93
|
+
writeGuid(view, 8, GUID_NULL);
|
|
94
|
+
view.setUint32(24, 1, true);
|
|
95
|
+
writeGuid(view, 28, propertySet.formatId);
|
|
96
|
+
view.setUint32(44, 48, true);
|
|
97
|
+
streamBytes.set(propertySetBytes, 48);
|
|
98
|
+
return streamBytes;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { PropertySetWriteError, writePropertySetStream };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "archive-codec",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "ZIP-in-ZIP recursive walking with depth and cumulative decompressed-size guards,
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "ZIP-in-ZIP recursive walking with depth and cumulative decompressed-size guards, bounded classic OLE compound-file ([MS-CFB]) reading and writing, and [MS-OLEPS] Property Set Stream reading and writing - zero document-format knowledge, the archive and container utility package for the documents.js family.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"packageManager": "pnpm@11.6.0",
|
|
69
69
|
"dependencies": {
|
|
70
|
+
"document-schema.js": "^5.5.1",
|
|
70
71
|
"fflate": "^0.8.2"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|