@johnhenry/sitefile 0.0.2 → 0.0.4
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/CHANGELOG.md +516 -0
- package/README.md +59 -9
- package/lib/src/archive-writers.d.ts +12 -2
- package/lib/src/archive-writers.js +53 -10
- package/lib/src/bake.d.ts +2 -0
- package/lib/src/bake.js +30 -1
- package/lib/src/bcrypt.d.ts +25 -0
- package/lib/src/bcrypt.js +201 -0
- package/lib/src/canonical.d.ts +19 -0
- package/lib/src/canonical.js +60 -0
- package/lib/src/car.d.ts +34 -0
- package/lib/src/car.js +203 -0
- package/lib/src/checklinks.js +8 -2
- package/lib/src/cli/bake.js +4 -3
- package/lib/src/cli/build-image.d.ts +1 -0
- package/lib/src/cli/build-image.js +1 -0
- package/lib/src/cli/common.js +4 -1
- package/lib/src/cli/hosts.d.ts +5 -0
- package/lib/src/cli/hosts.js +78 -0
- package/lib/src/cli/images.js +23 -5
- package/lib/src/cli/import-config.d.ts +2 -0
- package/lib/src/cli/import-config.js +56 -0
- package/lib/src/cli/index.d.ts +6 -1
- package/lib/src/cli/index.js +34 -2
- package/lib/src/cli/integrity.d.ts +2 -0
- package/lib/src/cli/integrity.js +77 -0
- package/lib/src/cli/network.d.ts +7 -0
- package/lib/src/cli/network.js +14 -3
- package/lib/src/cli/serve-keys.d.ts +39 -0
- package/lib/src/cli/serve-keys.js +106 -0
- package/lib/src/cli/serve-worker.js +119 -8
- package/lib/src/cli/servers.d.ts +130 -1
- package/lib/src/cli/servers.js +754 -72
- package/lib/src/cli/up.d.ts +2 -0
- package/lib/src/cli/up.js +193 -0
- package/lib/src/cli/watch.d.ts +14 -1
- package/lib/src/cli/watch.js +20 -3
- package/lib/src/cli.js +138 -18
- package/lib/src/csp.d.ts +17 -0
- package/lib/src/csp.js +52 -0
- package/lib/src/dictionary.d.ts +16 -0
- package/lib/src/dictionary.js +89 -0
- package/lib/src/epub.d.ts +5 -0
- package/lib/src/epub.js +113 -0
- package/lib/src/errors.d.ts +22 -9
- package/lib/src/errors.js +20 -1
- package/lib/src/executor.d.ts +31 -1
- package/lib/src/executor.js +231 -24
- package/lib/src/explain.js +33 -3
- package/lib/src/export-for.d.ts +42 -0
- package/lib/src/export-for.js +466 -0
- package/lib/src/export-formats.d.ts +2 -2
- package/lib/src/export-formats.js +52 -2
- package/lib/src/fingerprint.d.ts +3 -1
- package/lib/src/fingerprint.js +32 -5
- package/lib/src/host-config.d.ts +34 -0
- package/lib/src/host-config.js +645 -0
- package/lib/src/hosts.d.ts +47 -0
- package/lib/src/hosts.js +106 -0
- package/lib/src/hreflang.d.ts +25 -0
- package/lib/src/hreflang.js +72 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/integrity.d.ts +115 -0
- package/lib/src/integrity.js +273 -0
- package/lib/src/language/ast.d.ts +126 -3
- package/lib/src/language/ast.js +7 -1
- package/lib/src/language/parser.js +189 -7
- package/lib/src/language/validate.js +24 -0
- package/lib/src/links.d.ts +47 -0
- package/lib/src/links.js +289 -3
- package/lib/src/lint.d.ts +1 -1
- package/lib/src/lint.js +26 -1
- package/lib/src/mime-data.d.ts +2 -0
- package/lib/src/mime-data.js +92 -0
- package/lib/src/oci.d.ts +20 -2
- package/lib/src/oci.js +70 -28
- package/lib/src/outdated.d.ts +3 -0
- package/lib/src/outdated.js +4 -4
- package/lib/src/planner.d.ts +87 -2
- package/lib/src/planner.js +189 -8
- package/lib/src/plugins/cache.d.ts +11 -0
- package/lib/src/plugins/cache.js +29 -0
- package/lib/src/plugins/host.d.ts +51 -2
- package/lib/src/plugins/host.js +141 -16
- package/lib/src/plugins/wasm.js +1 -3
- package/lib/src/portable.d.ts +8 -0
- package/lib/src/portable.js +47 -0
- package/lib/src/precache.d.ts +33 -0
- package/lib/src/precache.js +75 -0
- package/lib/src/precompress.d.ts +19 -0
- package/lib/src/precompress.js +35 -0
- package/lib/src/qr.d.ts +18 -0
- package/lib/src/qr.js +372 -0
- package/lib/src/registry-ops.js +4 -2
- package/lib/src/reload-client.d.ts +2 -0
- package/lib/src/reload-client.js +419 -0
- package/lib/src/resources/archive.d.ts +37 -1
- package/lib/src/resources/archive.js +353 -71
- package/lib/src/resources/convert.js +3 -1
- package/lib/src/resources/https.d.ts +9 -1
- package/lib/src/resources/https.js +36 -0
- package/lib/src/resources/network.d.ts +25 -3
- package/lib/src/resources/network.js +77 -6
- package/lib/src/secrets.d.ts +12 -3
- package/lib/src/secrets.js +18 -5
- package/lib/src/serve-auth.d.ts +33 -0
- package/lib/src/serve-auth.js +120 -0
- package/lib/src/serve-rules.d.ts +83 -7
- package/lib/src/serve-rules.js +264 -53
- package/lib/src/server.d.ts +529 -11
- package/lib/src/server.js +1439 -57
- package/lib/src/servers-file.d.ts +36 -0
- package/lib/src/servers-file.js +101 -0
- package/lib/src/servers.d.ts +115 -7
- package/lib/src/servers.js +151 -29
- package/lib/src/single-file.d.ts +12 -0
- package/lib/src/single-file.js +147 -0
- package/lib/src/site.d.ts +58 -0
- package/lib/src/site.js +216 -5
- package/lib/src/store.js +9 -5
- package/lib/src/swbn.d.ts +10 -0
- package/lib/src/swbn.js +86 -0
- package/lib/src/toml.d.ts +17 -0
- package/lib/src/toml.js +323 -0
- package/lib/src/wacz.d.ts +6 -0
- package/lib/src/wacz.js +96 -0
- package/lib/src/warc.d.ts +28 -0
- package/lib/src/warc.js +252 -0
- package/lib/src/watch.d.ts +12 -1
- package/lib/src/watch.js +67 -1
- package/lib/src/wbn.d.ts +9 -1
- package/lib/src/wbn.js +23 -33
- package/lib/src/zstd.d.ts +4 -0
- package/lib/src/zstd.js +328 -0
- package/package.json +1 -1
package/lib/src/zstd.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* A small, deterministic Zstandard (RFC 8878) encoder for Compression Dictionary Transport deltas
|
|
4
|
+
* (`dcz`, issue #215), ported byte for byte as rust/src/zstd.rs. It is not libzstd: it trades ratio
|
|
5
|
+
* for a short, specified algorithm that both implementations run identically.
|
|
6
|
+
*
|
|
7
|
+
* - Matching: greedy, over the dictionary followed by the content. At each position the candidates are
|
|
8
|
+
* the previous match's offset, the same offset in the dictionary, offsets up to 16 away from the
|
|
9
|
+
* previous one (nearest first, smaller first), then the last position the same 4 bytes (a 32-bit little-endian key)
|
|
10
|
+
* started at; the longest match wins (the earlier candidate on a tie), if it is at least 4 bytes. Every
|
|
11
|
+
* position is inserted into the table, including those inside matches.
|
|
12
|
+
* - Blocks hold at most 128 KiB of output. A block is compressed (raw literals, sequences with the
|
|
13
|
+
* predefined FSE tables) unless its raw form is no larger, then it is stored raw. Offsets are always
|
|
14
|
+
* written as new offsets (offset + 3), never as repeat codes.
|
|
15
|
+
* - The frame has a window descriptor large enough for the dictionary and the content, a 4-byte
|
|
16
|
+
* content size and no checksum or dictionary ID (the dictionary is raw content, identified by the
|
|
17
|
+
* `dcz` header's SHA-256).
|
|
18
|
+
*/
|
|
19
|
+
const MAX_BLOCK = 128 * 1024;
|
|
20
|
+
const MIN_MATCH = 4;
|
|
21
|
+
/** How far from the previous match's offset to look (bytes inserted or deleted since). */
|
|
22
|
+
const NEAR = 16;
|
|
23
|
+
// ---------------------------------------------------------------- FSE (predefined tables only)
|
|
24
|
+
const LL_DIST = [4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1, -1, -1, -1, -1];
|
|
25
|
+
const ML_DIST = [
|
|
26
|
+
1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
|
|
27
|
+
-1,
|
|
28
|
+
];
|
|
29
|
+
const OF_DIST = [1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1];
|
|
30
|
+
const highbit = (v) => 31 - Math.clz32(v);
|
|
31
|
+
/** FSE compression table for a normalized distribution (as zstd's FSE_buildCTable builds it). */
|
|
32
|
+
function buildCTable(dist, log) {
|
|
33
|
+
const size = 1 << log;
|
|
34
|
+
const symbols = new Array(size).fill(0);
|
|
35
|
+
let high = size - 1;
|
|
36
|
+
for (let s = 0; s < dist.length; s++)
|
|
37
|
+
if (dist[s] === -1)
|
|
38
|
+
symbols[high--] = s;
|
|
39
|
+
const step = (size >> 1) + (size >> 3) + 3;
|
|
40
|
+
let pos = 0;
|
|
41
|
+
for (let s = 0; s < dist.length; s++) {
|
|
42
|
+
const n = dist[s];
|
|
43
|
+
for (let i = 0; i < n; i++) {
|
|
44
|
+
symbols[pos] = s;
|
|
45
|
+
do
|
|
46
|
+
pos = (pos + step) & (size - 1);
|
|
47
|
+
while (pos > high);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const cumul = [0];
|
|
51
|
+
for (let s = 0; s < dist.length; s++)
|
|
52
|
+
cumul.push(cumul[s] + (dist[s] === -1 ? 1 : dist[s]));
|
|
53
|
+
const next = new Array(size).fill(0);
|
|
54
|
+
const at = cumul.slice();
|
|
55
|
+
for (let u = 0; u < size; u++) {
|
|
56
|
+
const s = symbols[u];
|
|
57
|
+
next[at[s]++] = size + u;
|
|
58
|
+
}
|
|
59
|
+
const deltaNbBits = [];
|
|
60
|
+
const deltaFindState = [];
|
|
61
|
+
let total = 0;
|
|
62
|
+
for (let s = 0; s < dist.length; s++) {
|
|
63
|
+
const n = dist[s];
|
|
64
|
+
if (n === -1 || n === 1) {
|
|
65
|
+
deltaNbBits.push((log << 16) - size);
|
|
66
|
+
deltaFindState.push(total - 1);
|
|
67
|
+
total++;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const maxBitsOut = log - highbit(n - 1);
|
|
71
|
+
deltaNbBits.push((maxBitsOut << 16) - (n << maxBitsOut));
|
|
72
|
+
deltaFindState.push(total - n);
|
|
73
|
+
total += n;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { log, next, deltaNbBits, deltaFindState };
|
|
77
|
+
}
|
|
78
|
+
const LL_TABLE = buildCTable(LL_DIST, 6);
|
|
79
|
+
const ML_TABLE = buildCTable(ML_DIST, 6);
|
|
80
|
+
const OF_TABLE = buildCTable(OF_DIST, 5);
|
|
81
|
+
/** Little-endian bit writer (zstd's BIT_CStream). */
|
|
82
|
+
class Bits {
|
|
83
|
+
out = [];
|
|
84
|
+
acc = 0n;
|
|
85
|
+
n = 0;
|
|
86
|
+
add(value, bits) {
|
|
87
|
+
if (bits === 0)
|
|
88
|
+
return;
|
|
89
|
+
this.acc |= (BigInt(value) & ((1n << BigInt(bits)) - 1n)) << BigInt(this.n);
|
|
90
|
+
this.n += bits;
|
|
91
|
+
while (this.n >= 8) {
|
|
92
|
+
this.out.push(Number(this.acc & 0xffn));
|
|
93
|
+
this.acc >>= 8n;
|
|
94
|
+
this.n -= 8;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** The end mark (a 1 bit), then the last partial byte. */
|
|
98
|
+
close() {
|
|
99
|
+
this.add(1, 1);
|
|
100
|
+
if (this.n > 0)
|
|
101
|
+
this.out.push(Number(this.acc & 0xffn));
|
|
102
|
+
return new Uint8Array(this.out);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
class FseState {
|
|
106
|
+
t;
|
|
107
|
+
value = 0;
|
|
108
|
+
constructor(t) {
|
|
109
|
+
this.t = t;
|
|
110
|
+
}
|
|
111
|
+
init(symbol) {
|
|
112
|
+
const nbBitsOut = (this.t.deltaNbBits[symbol] + (1 << 15)) >> 16;
|
|
113
|
+
const v = (nbBitsOut << 16) - this.t.deltaNbBits[symbol];
|
|
114
|
+
this.value = this.t.next[(v >> nbBitsOut) + this.t.deltaFindState[symbol]];
|
|
115
|
+
}
|
|
116
|
+
encode(bits, symbol) {
|
|
117
|
+
const nbBitsOut = (this.value + this.t.deltaNbBits[symbol]) >> 16;
|
|
118
|
+
bits.add(this.value, nbBitsOut);
|
|
119
|
+
this.value = this.t.next[(this.value >> nbBitsOut) + this.t.deltaFindState[symbol]];
|
|
120
|
+
}
|
|
121
|
+
flush(bits) {
|
|
122
|
+
bits.add(this.value, this.t.log);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// ---------------------------------------------------------------- codes
|
|
126
|
+
const LL_BASE = [16, 18, 20, 22, 24, 28, 32, 40, 48, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];
|
|
127
|
+
const LL_EXTRA = [1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
|
128
|
+
const ML_BASE = [35, 37, 39, 41, 43, 47, 51, 59, 67, 83, 99, 131, 259, 515, 1027, 2051, 4099, 8195, 16387, 32771, 65539];
|
|
129
|
+
const ML_EXTRA = [1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
|
130
|
+
/** [code, extra bits, extra value] of a literal length. */
|
|
131
|
+
function llCode(ll) {
|
|
132
|
+
if (ll < 16)
|
|
133
|
+
return [ll, 0, 0];
|
|
134
|
+
let i = LL_BASE.length - 1;
|
|
135
|
+
while (LL_BASE[i] > ll)
|
|
136
|
+
i--;
|
|
137
|
+
return [16 + i, LL_EXTRA[i], ll - LL_BASE[i]];
|
|
138
|
+
}
|
|
139
|
+
/** [code, extra bits, extra value] of a match length (at least 3). */
|
|
140
|
+
function mlCode(ml) {
|
|
141
|
+
if (ml < 35)
|
|
142
|
+
return [ml - 3, 0, 0];
|
|
143
|
+
let i = ML_BASE.length - 1;
|
|
144
|
+
while (ML_BASE[i] > ml)
|
|
145
|
+
i--;
|
|
146
|
+
return [32 + i, ML_EXTRA[i], ml - ML_BASE[i]];
|
|
147
|
+
}
|
|
148
|
+
// ---------------------------------------------------------------- blocks
|
|
149
|
+
function literalsHeader(n) {
|
|
150
|
+
if (n < 32)
|
|
151
|
+
return [n << 3];
|
|
152
|
+
if (n < 4096)
|
|
153
|
+
return [(1 << 2) | ((n & 0xf) << 4), n >> 4];
|
|
154
|
+
return [(3 << 2) | ((n & 0xf) << 4), (n >> 4) & 0xff, n >> 12];
|
|
155
|
+
}
|
|
156
|
+
function sequencesHeader(n) {
|
|
157
|
+
if (n < 128)
|
|
158
|
+
return [n];
|
|
159
|
+
if (n < 0x7f00)
|
|
160
|
+
return [(n >> 8) + 0x80, n & 0xff];
|
|
161
|
+
return [0xff, (n - 0x7f00) & 0xff, (n - 0x7f00) >> 8];
|
|
162
|
+
}
|
|
163
|
+
function concat(parts) {
|
|
164
|
+
let n = 0;
|
|
165
|
+
for (const p of parts)
|
|
166
|
+
n += p.length;
|
|
167
|
+
const out = new Uint8Array(n);
|
|
168
|
+
let o = 0;
|
|
169
|
+
for (const p of parts) {
|
|
170
|
+
out.set(p, o);
|
|
171
|
+
o += p.length;
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
function compressedBlock(literals, seqs) {
|
|
176
|
+
const head = literalsHeader(literals.length);
|
|
177
|
+
const seqHead = sequencesHeader(seqs.length);
|
|
178
|
+
if (seqs.length === 0)
|
|
179
|
+
return concat([head, literals, seqHead]);
|
|
180
|
+
const modes = [0]; // predefined modes for literal lengths, offsets and match lengths
|
|
181
|
+
const codes = seqs.map((s) => {
|
|
182
|
+
const offBase = s.offset + 3;
|
|
183
|
+
const of = highbit(offBase);
|
|
184
|
+
return { ll: llCode(s.ll), ml: mlCode(s.ml), of: [of, of, offBase - (1 << of)] };
|
|
185
|
+
});
|
|
186
|
+
const bits = new Bits();
|
|
187
|
+
const ll = new FseState(LL_TABLE);
|
|
188
|
+
const ml = new FseState(ML_TABLE);
|
|
189
|
+
const of = new FseState(OF_TABLE);
|
|
190
|
+
const last = codes[codes.length - 1];
|
|
191
|
+
ml.init(last.ml[0]);
|
|
192
|
+
of.init(last.of[0]);
|
|
193
|
+
ll.init(last.ll[0]);
|
|
194
|
+
const extras = (c) => {
|
|
195
|
+
bits.add(c.ll[2], c.ll[1]);
|
|
196
|
+
bits.add(c.ml[2], c.ml[1]);
|
|
197
|
+
bits.add(c.of[2], c.of[1]);
|
|
198
|
+
};
|
|
199
|
+
extras(last);
|
|
200
|
+
for (let i = codes.length - 2; i >= 0; i--) {
|
|
201
|
+
const c = codes[i];
|
|
202
|
+
of.encode(bits, c.of[0]);
|
|
203
|
+
ml.encode(bits, c.ml[0]);
|
|
204
|
+
ll.encode(bits, c.ll[0]);
|
|
205
|
+
extras(c);
|
|
206
|
+
}
|
|
207
|
+
ml.flush(bits);
|
|
208
|
+
of.flush(bits);
|
|
209
|
+
ll.flush(bits);
|
|
210
|
+
return concat([head, literals, seqHead, modes, bits.close()]);
|
|
211
|
+
}
|
|
212
|
+
function blockHeader(last, type, size) {
|
|
213
|
+
const v = (last ? 1 : 0) | (type << 1) | (size << 3);
|
|
214
|
+
return [v & 0xff, (v >> 8) & 0xff, (v >> 16) & 0xff];
|
|
215
|
+
}
|
|
216
|
+
/** One frame of `content` compressed against the raw-content `dictionary`. */
|
|
217
|
+
export function zstdCompress(content, dictionary = new Uint8Array(0)) {
|
|
218
|
+
const all = new Uint8Array(dictionary.length + content.length);
|
|
219
|
+
all.set(dictionary, 0);
|
|
220
|
+
all.set(content, dictionary.length);
|
|
221
|
+
const key = (p) => (all[p] | (all[p + 1] << 8) | (all[p + 2] << 16) | (all[p + 3] << 24)) >>> 0;
|
|
222
|
+
const table = new Map();
|
|
223
|
+
const insert = (p) => {
|
|
224
|
+
if (p + MIN_MATCH <= all.length)
|
|
225
|
+
table.set(key(p), p);
|
|
226
|
+
};
|
|
227
|
+
for (let p = 0; p < dictionary.length; p++)
|
|
228
|
+
insert(p);
|
|
229
|
+
const out = [[0x28, 0xb5, 0x2f, 0xfd]];
|
|
230
|
+
// Window: the smallest power of two (at least 1 KiB) covering the dictionary and the content.
|
|
231
|
+
const need = Math.max(all.length, 1);
|
|
232
|
+
let windowLog = 10;
|
|
233
|
+
while (2 ** windowLog < need)
|
|
234
|
+
windowLog++;
|
|
235
|
+
out.push([0x80, (windowLog - 10) << 3]); // FCS field 4 bytes, not single segment, no checksum, no dict ID
|
|
236
|
+
out.push([content.length & 0xff, (content.length >>> 8) & 0xff, (content.length >>> 16) & 0xff, (content.length >>> 24) & 0xff]);
|
|
237
|
+
let pos = dictionary.length;
|
|
238
|
+
const end = all.length;
|
|
239
|
+
let lastOffset = 0;
|
|
240
|
+
if (pos === end) {
|
|
241
|
+
out.push(blockHeader(true, 0, 0));
|
|
242
|
+
return concat(out);
|
|
243
|
+
}
|
|
244
|
+
while (pos < end) {
|
|
245
|
+
const blockEnd = Math.min(end, pos + MAX_BLOCK);
|
|
246
|
+
const blockStart = pos;
|
|
247
|
+
const literals = []; // at most MAX_BLOCK
|
|
248
|
+
const seqs = [];
|
|
249
|
+
let run = 0;
|
|
250
|
+
while (pos < blockEnd) {
|
|
251
|
+
let len = 0;
|
|
252
|
+
let cand = -1;
|
|
253
|
+
const matchLen = (c) => {
|
|
254
|
+
let n = 0;
|
|
255
|
+
while (pos + n < blockEnd && all[c + n] === all[pos + n])
|
|
256
|
+
n++;
|
|
257
|
+
return n;
|
|
258
|
+
};
|
|
259
|
+
// The previous match's offset first (an edited file keeps its alignment), then the hash table.
|
|
260
|
+
if (lastOffset > 0 && pos - lastOffset >= 0) {
|
|
261
|
+
len = matchLen(pos - lastOffset);
|
|
262
|
+
cand = pos - lastOffset;
|
|
263
|
+
}
|
|
264
|
+
const tryOffset = (off) => {
|
|
265
|
+
if (off <= 0 || pos - off < 0 || pos - off === cand)
|
|
266
|
+
return;
|
|
267
|
+
const n = matchLen(pos - off);
|
|
268
|
+
if (n > len) {
|
|
269
|
+
len = n;
|
|
270
|
+
cand = pos - off;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
// The same place in the dictionary (the previous version of the file), then offsets near the
|
|
274
|
+
// previous one (a small insertion or deletion since the last match).
|
|
275
|
+
tryOffset(dictionary.length);
|
|
276
|
+
if (lastOffset > 0) {
|
|
277
|
+
for (let d = 1; d <= NEAR; d++) {
|
|
278
|
+
tryOffset(lastOffset - d);
|
|
279
|
+
tryOffset(lastOffset + d);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (pos + MIN_MATCH <= end) {
|
|
283
|
+
const c = table.get(key(pos));
|
|
284
|
+
if (c !== undefined && c !== cand) {
|
|
285
|
+
const n = matchLen(c);
|
|
286
|
+
if (n > len) {
|
|
287
|
+
len = n;
|
|
288
|
+
cand = c;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (len >= MIN_MATCH) {
|
|
293
|
+
lastOffset = pos - cand;
|
|
294
|
+
seqs.push({ ll: run, ml: len, offset: pos - cand });
|
|
295
|
+
run = 0;
|
|
296
|
+
for (let k = 0; k < len; k++)
|
|
297
|
+
insert(pos + k);
|
|
298
|
+
pos += len;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
literals.push(all[pos]);
|
|
302
|
+
run++;
|
|
303
|
+
insert(pos);
|
|
304
|
+
pos++;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const raw = all.subarray(blockStart, blockEnd);
|
|
308
|
+
// Trailing literals after the last sequence are part of the literals section.
|
|
309
|
+
const block = compressedBlock(new Uint8Array(literals), seqs);
|
|
310
|
+
const last = blockEnd === end;
|
|
311
|
+
if (block.length < raw.length)
|
|
312
|
+
out.push(blockHeader(last, 2, block.length), block);
|
|
313
|
+
else
|
|
314
|
+
out.push(blockHeader(last, 0, raw.length), raw);
|
|
315
|
+
}
|
|
316
|
+
return concat(out);
|
|
317
|
+
}
|
|
318
|
+
/** The `dcz` header: a skippable-frame magic, then the SHA-256 of the dictionary. */
|
|
319
|
+
export function dczEncode(content, dictionary) {
|
|
320
|
+
const hash = createHash('sha256').update(dictionary).digest();
|
|
321
|
+
const frame = zstdCompress(content, dictionary);
|
|
322
|
+
const out = new Uint8Array(40 + frame.length);
|
|
323
|
+
out.set([0x5e, 0x2a, 0x4d, 0x18, 0x20, 0x00, 0x00, 0x00], 0);
|
|
324
|
+
out.set(hash, 8);
|
|
325
|
+
out.set(frame, 40);
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=zstd.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/sitefile",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Docker-inspired static artifact builder: compose immutable file trees from local and remote sources, render templates, and export a deployable site. No container runtime, no shell, no runtime dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static-site",
|