polite-crawler 0.6.2 → 0.7.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 +66 -1
- package/build/api.d.mts +274 -20
- package/build/api.mjs +455 -4
- package/build/api.mjs.map +1 -1
- package/build/{cli-daemon-DBvq5TU3.mjs → cli-daemon-Bke7kU1e.mjs} +2 -2
- package/build/{cli-daemon-DBvq5TU3.mjs.map → cli-daemon-Bke7kU1e.mjs.map} +1 -1
- package/build/{cli-recipes-C--_YyuP.mjs → cli-recipes-CUFd9ORK.mjs} +2 -2
- package/build/{cli-recipes-C--_YyuP.mjs.map → cli-recipes-CUFd9ORK.mjs.map} +1 -1
- package/build/cli.mjs +7 -7
- package/build/{daemon-BkJp3wXR.mjs → daemon-Dh32XlZq.mjs} +3 -3
- package/build/{daemon-BkJp3wXR.mjs.map → daemon-Dh32XlZq.mjs.map} +1 -1
- package/build/{diff-DcbpHrxv.mjs → diff-ZEIt8xv3.mjs} +2 -2
- package/build/{diff-DcbpHrxv.mjs.map → diff-ZEIt8xv3.mjs.map} +1 -1
- package/build/{extract-DpycIF0M.mjs → extract-B_Tsv1UC.mjs} +3 -3
- package/build/{extract-DpycIF0M.mjs.map → extract-B_Tsv1UC.mjs.map} +1 -1
- package/build/html.d.mts +83 -2
- package/build/html.mjs +844 -1
- package/build/html.mjs.map +1 -0
- package/build/index.d.mts +15 -10
- package/build/index.mjs +12 -11
- package/build/{open-BIvV3pHE.mjs → open-Dx1gCR6l.mjs} +77 -55
- package/build/open-Dx1gCR6l.mjs.map +1 -0
- package/build/politeness.d.mts +33 -0
- package/build/politeness.mjs.map +1 -1
- package/build/{recipe-rECpzNa-.mjs → recipe-BO3V_1Kr.mjs} +4 -4
- package/build/{recipe-rECpzNa-.mjs.map → recipe-BO3V_1Kr.mjs.map} +1 -1
- package/build/{recipe-product-tVKjy4xu.mjs → recipe-product-BOQMCTGh.mjs} +6 -5
- package/build/{recipe-product-tVKjy4xu.mjs.map → recipe-product-BOQMCTGh.mjs.map} +1 -1
- package/build/{runtime-Hyr9qD0-.mjs → runtime-BVC7iOG4.mjs} +4 -3
- package/build/{runtime-Hyr9qD0-.mjs.map → runtime-BVC7iOG4.mjs.map} +1 -1
- package/build/text.d.mts +10 -0
- package/build/text.mjs +188 -0
- package/build/text.mjs.map +1 -0
- package/build/{version-D1VudHdM.mjs → version-DxUGcHQr.mjs} +2 -2
- package/build/{version-D1VudHdM.mjs.map → version-DxUGcHQr.mjs.map} +1 -1
- package/build/{wacz-D_Onr46C.mjs → wacz-DjgklRod.mjs} +3 -3
- package/build/{wacz-D_Onr46C.mjs.map → wacz-DjgklRod.mjs.map} +1 -1
- package/build/{warc-l7lECYMZ.mjs → warc-CgkNdXyG.mjs} +2 -2
- package/build/{warc-l7lECYMZ.mjs.map → warc-CgkNdXyG.mjs.map} +1 -1
- package/package.json +7 -1
- package/build/html-CawWTgMQ.mjs +0 -1030
- package/build/html-CawWTgMQ.mjs.map +0 -1
- package/build/html-oS_ueu9U.d.mts +0 -92
- package/build/open-BIvV3pHE.mjs.map +0 -1
package/build/text.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function gives the WHATWG name of the encoding of a body, for example `utf-8` or
|
|
3
|
+
* `windows-1252`. The function `decodeBody` uses it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const bodyEncoding: (bytes: Uint8Array, contentType: string | null) => string;
|
|
6
|
+
/**
|
|
7
|
+
* This function decodes the body of a response. It reads the encoding from the byte order mark,
|
|
8
|
+
* the `Content-Type` header and the document, with `bodyEncoding`. It does not throw.
|
|
9
|
+
*/
|
|
10
|
+
export declare const decodeBody: (bytes: Uint8Array, contentType: string | null) => string;
|
package/build/text.mjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// src/text.ts
|
|
2
|
+
/**
|
|
3
|
+
* The body decoder changes the bytes of a response into text. It finds the encoding in this order,
|
|
4
|
+
* as the WHATWG encoding rules and the browsers do:
|
|
5
|
+
*
|
|
6
|
+
* 1. A byte order mark.
|
|
7
|
+
* 2. The `charset` of the `Content-Type` header.
|
|
8
|
+
* 3. A `<meta charset>` or `http-equiv` declaration in the first 2,048 bytes of an HTML page, or the
|
|
9
|
+
* encoding of an XML declaration.
|
|
10
|
+
* 4. UTF-8 when the bytes are UTF-8, and windows-1252 when they are not.
|
|
11
|
+
*
|
|
12
|
+
* It uses only `TextDecoder`, so it operates in a browser too. A byte that the encoding does not
|
|
13
|
+
* know becomes U+FFFD. The decoder does not throw.
|
|
14
|
+
*/
|
|
15
|
+
const PRESCAN_BYTES = 2048;
|
|
16
|
+
/** This function gives the WHATWG name of an encoding label, or undefined when the runtime does not know the label. */
|
|
17
|
+
const encodingOf = (label) => {
|
|
18
|
+
try {
|
|
19
|
+
return new TextDecoder(label.trim().toLowerCase()).encoding;
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const bomOf = (bytes) => {
|
|
25
|
+
if (bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) return "utf-8";
|
|
26
|
+
if (bytes[0] === 254 && bytes[1] === 255) return "utf-16be";
|
|
27
|
+
if (bytes[0] === 255 && bytes[1] === 254) return "utf-16le";
|
|
28
|
+
};
|
|
29
|
+
/** This function gives the `charset` parameter of a media type, or undefined. */
|
|
30
|
+
const charsetOf = (contentType) => {
|
|
31
|
+
if (contentType === null) return void 0;
|
|
32
|
+
const match = /;\s*charset\s*=\s*(?:"([^"]*)"|([^\s;"]+))/i.exec(contentType.slice(0, 512));
|
|
33
|
+
return match?.[1] ?? match?.[2] ?? void 0;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* This function removes each comment (`<!--` to the next `-->`) of a text, in one pass from the
|
|
37
|
+
* start. It uses no regular expression, so its time is linear.
|
|
38
|
+
*/
|
|
39
|
+
const withoutComments = (text) => {
|
|
40
|
+
let out = "";
|
|
41
|
+
let at = 0;
|
|
42
|
+
for (let open = text.indexOf("<!--"); open !== -1; open = text.indexOf("<!--", at)) {
|
|
43
|
+
const close = text.indexOf("-->", open + 4);
|
|
44
|
+
if (close === -1) break;
|
|
45
|
+
out += text.slice(at, open);
|
|
46
|
+
at = close + 3;
|
|
47
|
+
}
|
|
48
|
+
return out + text.slice(at);
|
|
49
|
+
};
|
|
50
|
+
/** This function reads the encoding that the start of an HTML or XML document declares. */
|
|
51
|
+
const declaredCharset = (bytes) => {
|
|
52
|
+
let head = "";
|
|
53
|
+
const end = Math.min(bytes.length, PRESCAN_BYTES);
|
|
54
|
+
for (let index = 0; index < end; index += 1) head += String.fromCharCode(bytes[index]);
|
|
55
|
+
const xml = /^\s*<\?xml[^>]*?\bencoding\s*=\s*["']([^"']+)["']/i.exec(head);
|
|
56
|
+
if (xml !== null) return xml[1];
|
|
57
|
+
const markup = withoutComments(head);
|
|
58
|
+
return /<meta\b[^>]*?\bcharset\s*=\s*(?:["']\s*)?([A-Za-z0-9_:.+-]+)/i.exec(markup)?.[1];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* This function counts the UTF-8 sequences of more than one byte, and the bytes that no UTF-8
|
|
62
|
+
* sequence explains. An incomplete sequence at the end is no error: a body cut at its size limit
|
|
63
|
+
* ends so.
|
|
64
|
+
*/
|
|
65
|
+
const utf8Evidence = (bytes) => {
|
|
66
|
+
let multibyte = 0;
|
|
67
|
+
let invalid = 0;
|
|
68
|
+
let index = 0;
|
|
69
|
+
while (index < bytes.length) {
|
|
70
|
+
const lead = bytes[index];
|
|
71
|
+
if (lead < 128) {
|
|
72
|
+
index += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const need = lead >= 194 && lead <= 223 ? 1 : lead >= 224 && lead <= 239 ? 2 : lead >= 240 && lead <= 244 ? 3 : 0;
|
|
76
|
+
if (need === 0) {
|
|
77
|
+
invalid += 1;
|
|
78
|
+
index += 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const low = lead === 224 ? 160 : lead === 240 ? 144 : 128;
|
|
82
|
+
const high = lead === 237 ? 159 : lead === 244 ? 143 : 191;
|
|
83
|
+
let ok = true;
|
|
84
|
+
let at = 1;
|
|
85
|
+
while (at <= need && index + at < bytes.length) {
|
|
86
|
+
const next = bytes[index + at];
|
|
87
|
+
if (at === 1 ? next < low || next > high : next < 128 || next > 191) {
|
|
88
|
+
ok = false;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
at += 1;
|
|
92
|
+
}
|
|
93
|
+
if (ok && at <= need) break;
|
|
94
|
+
if (ok) {
|
|
95
|
+
multibyte += 1;
|
|
96
|
+
index += need + 1;
|
|
97
|
+
} else {
|
|
98
|
+
invalid += 1;
|
|
99
|
+
index += 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
multibyte,
|
|
104
|
+
invalid
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* This function gives the WHATWG name of the encoding of a body, for example `utf-8` or
|
|
109
|
+
* `windows-1252`. The function `decodeBody` uses it.
|
|
110
|
+
*/
|
|
111
|
+
const bodyEncoding = (bytes, contentType) => {
|
|
112
|
+
const bom = bomOf(bytes);
|
|
113
|
+
if (bom !== void 0) return bom;
|
|
114
|
+
const header = charsetOf(contentType);
|
|
115
|
+
const fromHeader = header === void 0 ? void 0 : encodingOf(header);
|
|
116
|
+
if (fromHeader !== void 0) return fromHeader;
|
|
117
|
+
if (contentType === null || /html|xml/i.test(contentType)) {
|
|
118
|
+
const label = declaredCharset(bytes);
|
|
119
|
+
let declared = label === void 0 ? void 0 : encodingOf(label);
|
|
120
|
+
if (declared?.startsWith("utf-16") === true) declared = "utf-8";
|
|
121
|
+
if (declared === "x-user-defined") declared = "windows-1252";
|
|
122
|
+
if (declared === "utf-8") return declared;
|
|
123
|
+
if (declared !== void 0) {
|
|
124
|
+
const evidence = utf8Evidence(bytes);
|
|
125
|
+
return evidence.invalid === 0 && evidence.multibyte > 0 ? "utf-8" : declared;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (/json/i.test(contentType ?? "")) return "utf-8";
|
|
129
|
+
const evidence = utf8Evidence(bytes);
|
|
130
|
+
return evidence.invalid > 0 && evidence.invalid >= evidence.multibyte ? "windows-1252" : "utf-8";
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* These are the characters of the bytes 0x80 to 0x9F in windows-1252, from the WHATWG index.
|
|
134
|
+
* Node.js 22 decodes windows-1252 as ISO-8859-1, which gives a control character for each of
|
|
135
|
+
* these bytes. A later runtime gives the correct characters, and then the map changes nothing.
|
|
136
|
+
*/
|
|
137
|
+
const WINDOWS_1252_HIGH = [
|
|
138
|
+
8364,
|
|
139
|
+
129,
|
|
140
|
+
8218,
|
|
141
|
+
402,
|
|
142
|
+
8222,
|
|
143
|
+
8230,
|
|
144
|
+
8224,
|
|
145
|
+
8225,
|
|
146
|
+
710,
|
|
147
|
+
8240,
|
|
148
|
+
352,
|
|
149
|
+
8249,
|
|
150
|
+
338,
|
|
151
|
+
141,
|
|
152
|
+
381,
|
|
153
|
+
143,
|
|
154
|
+
144,
|
|
155
|
+
8216,
|
|
156
|
+
8217,
|
|
157
|
+
8220,
|
|
158
|
+
8221,
|
|
159
|
+
8226,
|
|
160
|
+
8211,
|
|
161
|
+
8212,
|
|
162
|
+
732,
|
|
163
|
+
8482,
|
|
164
|
+
353,
|
|
165
|
+
8250,
|
|
166
|
+
339,
|
|
167
|
+
157,
|
|
168
|
+
382,
|
|
169
|
+
376
|
|
170
|
+
];
|
|
171
|
+
const C1_CONTROLS = new RegExp(`[${String.fromCharCode(128)}-${String.fromCharCode(159)}]`, "g");
|
|
172
|
+
const repairWindows1252 = (text) => text.replace(C1_CONTROLS, (char) => String.fromCharCode(WINDOWS_1252_HIGH[char.charCodeAt(0) - 128]));
|
|
173
|
+
/**
|
|
174
|
+
* This function decodes the body of a response. It reads the encoding from the byte order mark,
|
|
175
|
+
* the `Content-Type` header and the document, with `bodyEncoding`. It does not throw.
|
|
176
|
+
*/
|
|
177
|
+
const decodeBody = (bytes, contentType) => {
|
|
178
|
+
const encoding = bodyEncoding(bytes, contentType);
|
|
179
|
+
try {
|
|
180
|
+
const text = new TextDecoder(encoding, { fatal: false }).decode(bytes);
|
|
181
|
+
return encoding === "windows-1252" ? repairWindows1252(text) : text;
|
|
182
|
+
} catch {
|
|
183
|
+
return new TextDecoder("utf-8", { fatal: false }).decode(bytes);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
export { bodyEncoding, decodeBody };
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=text.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.mjs","names":[],"sources":["../src/text.ts"],"sourcesContent":["/**\n * The body decoder changes the bytes of a response into text. It finds the encoding in this order,\n * as the WHATWG encoding rules and the browsers do:\n *\n * 1. A byte order mark.\n * 2. The `charset` of the `Content-Type` header.\n * 3. A `<meta charset>` or `http-equiv` declaration in the first 2,048 bytes of an HTML page, or the\n * encoding of an XML declaration.\n * 4. UTF-8 when the bytes are UTF-8, and windows-1252 when they are not.\n *\n * It uses only `TextDecoder`, so it operates in a browser too. A byte that the encoding does not\n * know becomes U+FFFD. The decoder does not throw.\n */\n\nconst PRESCAN_BYTES = 2048;\n\n/** This function gives the WHATWG name of an encoding label, or undefined when the runtime does not know the label. */\nconst encodingOf = (label: string): string | undefined => {\n try {\n return new TextDecoder(label.trim().toLowerCase()).encoding;\n } catch {\n return undefined;\n }\n};\n\nconst bomOf = (bytes: Uint8Array): string | undefined => {\n if (bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf) return \"utf-8\";\n if (bytes[0] === 0xfe && bytes[1] === 0xff) return \"utf-16be\";\n if (bytes[0] === 0xff && bytes[1] === 0xfe) return \"utf-16le\";\n return undefined;\n};\n\n/** This function gives the `charset` parameter of a media type, or undefined. */\nconst charsetOf = (contentType: string | null): string | undefined => {\n if (contentType === null) return undefined;\n const match = /;\\s*charset\\s*=\\s*(?:\"([^\"]*)\"|([^\\s;\"]+))/i.exec(contentType.slice(0, 512));\n return match?.[1] ?? match?.[2] ?? undefined;\n};\n\n/**\n * This function removes each comment (`<!--` to the next `-->`) of a text, in one pass from the\n * start. It uses no regular expression, so its time is linear.\n */\nconst withoutComments = (text: string): string => {\n let out = \"\";\n let at = 0;\n for (let open = text.indexOf(\"<!--\"); open !== -1; open = text.indexOf(\"<!--\", at)) {\n const close = text.indexOf(\"-->\", open + 4);\n // a comment that does not close stays, and no later comment can close\n if (close === -1) break;\n out += text.slice(at, open);\n at = close + 3;\n }\n return out + text.slice(at);\n};\n\n/** This function reads the encoding that the start of an HTML or XML document declares. */\nconst declaredCharset = (bytes: Uint8Array): string | undefined => {\n let head = \"\";\n const end = Math.min(bytes.length, PRESCAN_BYTES);\n for (let index = 0; index < end; index += 1) head += String.fromCharCode(bytes[index]!);\n const xml = /^\\s*<\\?xml[^>]*?\\bencoding\\s*=\\s*[\"']([^\"']+)[\"']/i.exec(head);\n if (xml !== null) return xml[1];\n // a declaration inside a comment declares nothing\n const markup = withoutComments(head);\n // `<meta charset=x>`, and `<meta http-equiv=\"Content-Type\" content=\"text/html; charset=x\">`.\n // The spaces after a quote are a separate group, so two runs of spaces are never next to each\n // other. The time is linear in the length of the head (CodeQL alert 32).\n const meta = /<meta\\b[^>]*?\\bcharset\\s*=\\s*(?:[\"']\\s*)?([A-Za-z0-9_:.+-]+)/i.exec(markup);\n return meta?.[1];\n};\n\n/**\n * This function counts the UTF-8 sequences of more than one byte, and the bytes that no UTF-8\n * sequence explains. An incomplete sequence at the end is no error: a body cut at its size limit\n * ends so.\n */\nconst utf8Evidence = (\n bytes: Uint8Array,\n): { readonly multibyte: number; readonly invalid: number } => {\n let multibyte = 0;\n let invalid = 0;\n let index = 0;\n while (index < bytes.length) {\n const lead = bytes[index]!;\n if (lead < 0x80) {\n index += 1;\n continue;\n }\n const need =\n lead >= 0xc2 && lead <= 0xdf\n ? 1\n : lead >= 0xe0 && lead <= 0xef\n ? 2\n : lead >= 0xf0 && lead <= 0xf4\n ? 3\n : 0;\n if (need === 0) {\n invalid += 1;\n index += 1;\n continue;\n }\n // the second byte has a narrower range after E0, ED, F0 and F4\n const low = lead === 0xe0 ? 0xa0 : lead === 0xf0 ? 0x90 : 0x80;\n const high = lead === 0xed ? 0x9f : lead === 0xf4 ? 0x8f : 0xbf;\n let ok = true;\n let at = 1;\n while (at <= need && index + at < bytes.length) {\n const next = bytes[index + at]!;\n if (at === 1 ? next < low || next > high : next < 0x80 || next > 0xbf) {\n ok = false;\n break;\n }\n at += 1;\n }\n // the body ends inside the sequence\n if (ok && at <= need) break;\n if (ok) {\n multibyte += 1;\n index += need + 1;\n } else {\n invalid += 1;\n index += 1;\n }\n }\n return { multibyte, invalid };\n};\n\n/**\n * This function gives the WHATWG name of the encoding of a body, for example `utf-8` or\n * `windows-1252`. The function `decodeBody` uses it.\n */\nexport const bodyEncoding = (bytes: Uint8Array, contentType: string | null): string => {\n const bom = bomOf(bytes);\n if (bom !== undefined) return bom;\n const header = charsetOf(contentType);\n const fromHeader = header === undefined ? undefined : encodingOf(header);\n if (fromHeader !== undefined) return fromHeader;\n if (contentType === null || /html|xml/i.test(contentType)) {\n const label = declaredCharset(bytes);\n let declared = label === undefined ? undefined : encodingOf(label);\n // the HTML standard reads a UTF-16 declaration in ASCII-compatible bytes as UTF-8\n if (declared?.startsWith(\"utf-16\") === true) declared = \"utf-8\";\n if (declared === \"x-user-defined\") declared = \"windows-1252\";\n if (declared === \"utf-8\") return declared;\n if (declared !== undefined) {\n // A browser serialises the page it rendered as UTF-8, and the old declaration stays. UTF-8\n // with no error is almost never a legacy encoding by chance.\n const evidence = utf8Evidence(bytes);\n return evidence.invalid === 0 && evidence.multibyte > 0 ? \"utf-8\" : declared;\n }\n }\n if (/json/i.test(contentType ?? \"\")) return \"utf-8\";\n const evidence = utf8Evidence(bytes);\n return evidence.invalid > 0 && evidence.invalid >= evidence.multibyte ? \"windows-1252\" : \"utf-8\";\n};\n\n/**\n * These are the characters of the bytes 0x80 to 0x9F in windows-1252, from the WHATWG index.\n * Node.js 22 decodes windows-1252 as ISO-8859-1, which gives a control character for each of\n * these bytes. A later runtime gives the correct characters, and then the map changes nothing.\n */\nconst WINDOWS_1252_HIGH = [\n 0x20ac, 0x81, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x160, 0x2039, 0x152,\n 0x8d, 0x17d, 0x8f, 0x90, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122,\n 0x161, 0x203a, 0x153, 0x9d, 0x17e, 0x178,\n];\nconst C1_CONTROLS = new RegExp(`[${String.fromCharCode(0x80)}-${String.fromCharCode(0x9f)}]`, \"g\");\nconst repairWindows1252 = (text: string): string =>\n text.replace(C1_CONTROLS, (char) =>\n String.fromCharCode(WINDOWS_1252_HIGH[char.charCodeAt(0) - 0x80]!),\n );\n\n/**\n * This function decodes the body of a response. It reads the encoding from the byte order mark,\n * the `Content-Type` header and the document, with `bodyEncoding`. It does not throw.\n */\nexport const decodeBody = (bytes: Uint8Array, contentType: string | null): string => {\n const encoding = bodyEncoding(bytes, contentType);\n try {\n const text = new TextDecoder(encoding, { fatal: false }).decode(bytes);\n return encoding === \"windows-1252\" ? repairWindows1252(text) : text;\n } catch {\n // a runtime with a small ICU knows only a few encodings\n return new TextDecoder(\"utf-8\", { fatal: false }).decode(bytes);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,gBAAgB;;AAGtB,MAAM,cAAc,UAAsC;CACxD,IAAI;EACF,OAAO,IAAI,YAAY,MAAM,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;CACrD,QAAQ;EACN;CACF;AACF;AAEA,MAAM,SAAS,UAA0C;CACvD,IAAI,MAAM,OAAO,OAAQ,MAAM,OAAO,OA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,YAAY,IAAI,UAAU;EACtE;CACF;CACA,IAAI,QAAQ,KAAK,eAAe,EAAE,GAAG,OAAO;CAC5C,MAAM,WAAW,aAAa,KAAK;CACnC,OAAO,SAAS,UAAU,KAAK,SAAS,WAAW,SAAS,YAAY,iBAAiB;AAC3F;;;;;;AAOA,MAAM,oBAAoB;CACxB;CAAQ;CAAM;CAAQ;CAAO;CAAQ;CAAQ;CAAQ;CAAQ;CAAO;CAAQ;CAAO;CAAQ;CAC3F;CAAM;CAAO;CAAM;CAAM;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAO;CACxF;CAAO;CAAQ;CAAO;CAAM;CAAO;AACrC;AACA,MAAM,cAAc,IAAI,OAAO,IAAI,OAAO,aAAa,GAAI,EAAE,GAAG,OAAO,aAAa,GAAI,EAAE,IAAI,GAAG;AACjG,MAAM,qBAAqB,SACzB,KAAK,QAAQ,cAAc,SACzB,OAAO,aAAa,kBAAkB,KAAK,WAAW,CAAC,IAAI,IAAM,CACnE;;;;;AAMF,MAAa,cAAc,OAAmB,gBAAuC;CACnF,MAAM,WAAW,aAAa,OAAO,WAAW;CAChD,IAAI;EACF,MAAM,OAAO,IAAI,YAAY,UAAU,EAAE,OAAO,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK;EACrE,OAAO,aAAa,iBAAiB,kBAAkB,IAAI,IAAI;CACjE,QAAQ;EAEN,OAAO,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK;CAChE;AACF"}
|
|
@@ -31,11 +31,11 @@ const durationMs = (duration) => {
|
|
|
31
31
|
};
|
|
32
32
|
// src/version.ts
|
|
33
33
|
/** This is the version of the package. A test makes sure that it agrees with `package.json`. */
|
|
34
|
-
const VERSION = "0.
|
|
34
|
+
const VERSION = "0.7.0";
|
|
35
35
|
/** This is the product token that robots.txt rules match when an application gives no token. */
|
|
36
36
|
const DEFAULT_TOKEN = "PoliteCrawler";
|
|
37
37
|
/** This page tells a site owner what the crawler is and how to control it. */
|
|
38
38
|
const BOT_PAGE = "https://mark1russell7.github.io/crawler/bot/";
|
|
39
39
|
export { durationMs as i, DEFAULT_TOKEN as n, VERSION as r, BOT_PAGE as t };
|
|
40
40
|
|
|
41
|
-
//# sourceMappingURL=version-
|
|
41
|
+
//# sourceMappingURL=version-DxUGcHQr.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-
|
|
1
|
+
{"version":3,"file":"version-DxUGcHQr.mjs","names":[],"sources":["../src/duration.ts","../src/version.ts"],"sourcesContent":["/** A duration is a count of milliseconds, or a text, for example `\"30m\"`, `\"24h\"` or `\"7d\"`. */\nexport type Duration = number | string;\n\nconst UNITS: Readonly<Record<string, number>> = {\n ms: 1,\n s: 1000,\n m: 60_000,\n h: 3_600_000,\n d: 86_400_000,\n w: 604_800_000,\n};\n\n/**\n * This function changes a duration into milliseconds. The units are `ms`, `s`, `m` (minutes), `h`,\n * `d` and `w`, in any case. The unit `M` is an error, because a month is not a unit. A bare `0`\n * is zero. The function throws an error for a text that it cannot read.\n *\n * The options take a `Duration` (for example `\"10m\"`), and the crawler reads it. polite-crawler-mcp\n * reads the durations of its tools with it.\n *\n * @beta\n */\nexport const durationMs = (duration: Duration): number => {\n if (typeof duration === \"number\") {\n if (!Number.isFinite(duration) || duration < 0)\n throw new Error(`not a duration: ${String(duration)}`);\n return duration;\n }\n if (/^\\s*0+(\\.0+)?\\s*$/.test(duration)) return 0;\n const match = /^\\s*(\\d+(?:\\.\\d+)?)\\s*(ms|s|m|h|d|w)\\s*$/i.exec(duration);\n const unit = match?.[2];\n const factor = unit === undefined || unit === \"M\" ? undefined : UNITS[unit.toLowerCase()];\n if (match === null || factor === undefined) {\n throw new Error(\n `not a duration: \"${duration}\" (write a number and ms, s, m, h, d or w; m is minutes)`,\n );\n }\n return Number(match[1]) * factor;\n};\n","/** This is the version of the package. A test makes sure that it agrees with `package.json`. */\nexport const VERSION = \"0.7.0\";\n\n/** This is the product token that robots.txt rules match when an application gives no token. */\nexport const DEFAULT_TOKEN = \"PoliteCrawler\";\n\n/** This page tells a site owner what the crawler is and how to control it. */\nexport const BOT_PAGE = \"https://mark1russell7.github.io/crawler/bot/\";\n"],"mappings":";AAGA,MAAM,QAA0C;CAC9C,IAAI;CACJ,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;;;;;AAYA,MAAa,cAAc,aAA+B;CACxD,IAAI,OAAO,aAAa,UAAU;EAChC,IAAI,CAAC,OAAO,SAAS,QAAQ,KAAK,WAAW,GAC3C,MAAM,IAAI,MAAM,mBAAmB,OAAO,QAAQ,GAAG;EACvD,OAAO;CACT;CACA,IAAI,oBAAoB,KAAK,QAAQ,GAAG,OAAO;CAC/C,MAAM,QAAQ,4CAA4C,KAAK,QAAQ;CACvE,MAAM,OAAO,QAAQ;CACrB,MAAM,SAAS,SAAS,KAAA,KAAa,SAAS,MAAM,KAAA,IAAY,MAAM,KAAK,YAAY;CACvF,IAAI,UAAU,QAAQ,WAAW,KAAA,GAC/B,MAAM,IAAI,MACR,oBAAoB,SAAS,yDAC/B;CAEF,OAAO,OAAO,MAAM,EAAE,IAAI;AAC5B;;;ACrCA,MAAa,UAAU;;AAGvB,MAAa,gBAAgB;;AAG7B,MAAa,WAAW"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
|
|
2
2
|
import { cacheKeyOf } from "./urls.mjs";
|
|
3
|
-
import { r as VERSION } from "./version-
|
|
4
|
-
import { c as deflateFile, i as planArchive, l as memberOf, o as writeArchive, r as outputOf, s as TalliedFile, t as cdxjLine, u as writeZip } from "./warc-
|
|
3
|
+
import { r as VERSION } from "./version-DxUGcHQr.mjs";
|
|
4
|
+
import { c as deflateFile, i as planArchive, l as memberOf, o as writeArchive, r as outputOf, s as TalliedFile, t as cdxjLine, u as writeZip } from "./warc-CgkNdXyG.mjs";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import { basename, join } from "node:path";
|
|
@@ -270,4 +270,4 @@ const exportWacz = async (source, options) => {
|
|
|
270
270
|
};
|
|
271
271
|
export { wacz_exports as n, exportWacz as t };
|
|
272
272
|
|
|
273
|
-
//# sourceMappingURL=wacz-
|
|
273
|
+
//# sourceMappingURL=wacz-DjgklRod.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wacz-D_Onr46C.mjs","names":["NEWLINE"],"sources":["../src/sorter.ts","../src/wacz.ts"],"sourcesContent":["import { createReadStream } from \"node:fs\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nconst NEWLINE = 0x0a;\n\n/** This function compares two lines by their bytes. */\nconst byBytes = (a: Buffer, b: Buffer): number => Buffer.compare(a, b);\n\n/** This function reads a file line by line, as bytes. A line holds no line break. */\nasync function* linesOf(path: string): AsyncGenerator<Buffer> {\n let rest: Buffer | undefined;\n for await (const chunk of createReadStream(path) as AsyncIterable<Buffer>) {\n const data = rest === undefined ? chunk : Buffer.concat([rest, chunk]);\n rest = undefined;\n let start = 0;\n for (;;) {\n const end = data.indexOf(NEWLINE, start);\n if (end === -1) break;\n yield data.subarray(start, end);\n start = end + 1;\n }\n if (start < data.length) rest = Buffer.from(data.subarray(start));\n }\n if (rest !== undefined && rest.length > 0) yield rest;\n}\n\n/**\n * A line sorter sorts lines of text in the sequence of their UTF-8 bytes (the sequence of\n * `LC_ALL=C sort`). It keeps no more than `limit` bytes of lines in memory. When it has more, it\n * writes them to a sorted file in `dir`. At the end it merges the files. Thus its memory does not\n * grow with the count of lines. The WACZ export sorts its index and its page list with it.\n *\n * A line must not hold a line break.\n */\nexport class LineSorter {\n private lines: Buffer[] = [];\n private bytes = 0;\n private readonly runs: string[] = [];\n\n constructor(\n private readonly dir: string,\n private readonly limit: number = 8 * 1024 * 1024,\n ) {}\n\n /** This value is the count of sorted files that the sorter wrote. */\n get files(): number {\n return this.runs.length;\n }\n\n async add(line: string): Promise<void> {\n const bytes = Buffer.from(line, \"utf8\");\n if (bytes.includes(NEWLINE)) throw new Error(\"a line to sort holds a line break\");\n this.lines.push(bytes);\n // each line also costs an object in memory, so the count adds a little for each line\n this.bytes += bytes.length + 64;\n if (this.bytes >= this.limit) await this.spill();\n }\n\n private async spill(): Promise<void> {\n if (this.lines.length === 0) return;\n this.lines.sort(byBytes);\n await mkdir(this.dir, { recursive: true });\n const path = join(this.dir, `${String(this.runs.length)}.lines`);\n const parts: Buffer[] = [];\n const newline = Buffer.from([NEWLINE]);\n for (const line of this.lines) parts.push(line, newline);\n await writeFile(path, Buffer.concat(parts), { mode: 0o600 });\n this.runs.push(path);\n this.lines = [];\n this.bytes = 0;\n }\n\n /** This method gives each line in the sorted sequence. Use it one time, after the last `add`. */\n async *sorted(): AsyncGenerator<Buffer> {\n if (this.runs.length === 0) {\n const lines = this.lines.sort(byBytes);\n this.lines = [];\n yield* lines;\n return;\n }\n await this.spill();\n const readers = this.runs.map((path) => linesOf(path)[Symbol.asyncIterator]());\n const heads: Array<Buffer | undefined> = [];\n for (const reader of readers) heads.push((await reader.next()).value ?? undefined);\n for (;;) {\n let pick = -1;\n for (const [at, head] of heads.entries()) {\n if (head !== undefined && (pick === -1 || Buffer.compare(head, heads[pick]!) < 0))\n pick = at;\n }\n if (pick === -1) return;\n yield heads[pick]!;\n heads[pick] = (await readers[pick]!.next()).value ?? undefined;\n }\n }\n}\n","import { createHash } from \"node:crypto\";\nimport { mkdir, rename, rm } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport { LineSorter } from \"./sorter.ts\";\nimport { cacheKeyOf } from \"./urls.ts\";\nimport { VERSION } from \"./version.ts\";\nimport type { ArchiveCounts, ArchiveOptions, ArchiveSource } from \"./warc.ts\";\nimport { cdxjLine, outputOf, planArchive, writeArchive } from \"./warc.ts\";\nimport type { Tallied, ZipMember } from \"./zip.ts\";\nimport { TalliedFile, deflateFile, memberOf, writeZip } from \"./zip.ts\";\n\n/*\n * This module writes a WACZ 1.1.1 file: a ZIP with the WARC file, a sorted CDXJ index, a page list\n * and the data package with the SHA-256 of each part. Replay tools (ReplayWeb.page, pywb) open it.\n */\n\n/** This is the version of the WACZ specification that the export follows. */\nconst WACZ_VERSION = \"1.1.1\";\nconst WARC_NAME = \"data.warc.gz\";\nconst NEWLINE = Buffer.from(\"\\n\");\nconst TAB = 0x09;\nconst PAGES_HEADER = { format: \"json-pages-1.0\", id: \"pages\", title: \"All Pages\" };\n\n/** This is the result of `exportWacz`. */\nexport interface WaczResult extends ArchiveCounts {\n readonly format: \"wacz\";\n /** This value is the absolute path of the archive. */\n readonly out: string;\n readonly bytes: number;\n /** This value is the count of pages in `pages/pages.jsonl`: one for each document. */\n readonly pages: number;\n}\n\n/** This function writes lines to a file in batches of approximately 64 KiB. It gives the count of lines. */\nconst writeLines = async (file: TalliedFile, lines: AsyncIterable<Uint8Array>): Promise<number> => {\n let batch: Uint8Array[] = [];\n let size = 0;\n let count = 0;\n for await (const line of lines) {\n batch.push(line, NEWLINE);\n size += line.length + 1;\n count += 1;\n if (size >= 65_536) {\n await file.write(Buffer.concat(batch));\n batch = [];\n size = 0;\n }\n }\n if (batch.length > 0) await file.write(Buffer.concat(batch));\n return count;\n};\n\n/**\n * This function keeps the last line of each document. Each line is the key of the document, a tab,\n * the time, a tab and the JSON of the page. The sorter gives the lines of one key together, the\n * oldest first.\n */\nasync function* latestOf(lines: AsyncIterable<Buffer>): AsyncGenerator<Buffer> {\n let held: Buffer | undefined;\n let heldKey: Buffer | undefined;\n for await (const line of lines) {\n const key = line.subarray(0, line.indexOf(TAB));\n if (held !== undefined && heldKey !== undefined && !key.equals(heldKey)) {\n yield held.subarray(held.indexOf(TAB, heldKey.length + 1) + 1);\n }\n held = line;\n heldKey = key;\n }\n if (held !== undefined && heldKey !== undefined)\n yield held.subarray(held.indexOf(TAB, heldKey.length + 1) + 1);\n}\n\nconst resourceOf = (\n path: string,\n facts: Tallied,\n): {\n readonly name: string;\n readonly path: string;\n readonly hash: string;\n readonly bytes: number;\n} => ({\n name: basename(path).toLowerCase(),\n path,\n hash: `sha256:${facts.sha256}`,\n bytes: facts.size,\n});\n\n/**\n * This function writes the captures of a store as a WACZ 1.1.1 file. The ZIP holds these parts:\n *\n * - `archive/data.warc.gz`: the WARC file of `exportWarc`, stored with no more compression, so a\n * replay tool reads a record at its offset.\n * - `indexes/index.cdxj`: the index of the `response` and `revisit` records, sorted by SURT key.\n * - `pages/pages.jsonl`: one page for each document, at its latest capture.\n * - `datapackage.json` and `datapackage-digest.json`: the SHA-256 of each part, and of the package.\n *\n * The index and the page list are sorted on the disk, so the memory does not grow with the store.\n * The export writes temporary files beside `out` and removes them at the end.\n */\nexport const exportWacz = async (\n source: ArchiveSource,\n options: ArchiveOptions,\n): Promise<WaczResult> => {\n const plan = planArchive(source, options);\n const { target, temporary } = outputOf(options);\n const parts = `${temporary}.parts`;\n await mkdir(parts, { recursive: true, mode: 0o700 });\n try {\n const created = new Date();\n const warc = await TalliedFile.create(join(parts, WARC_NAME));\n const index = new LineSorter(join(parts, \"index\"));\n const pages = new LineSorter(join(parts, \"pages\"));\n let counts: ArchiveCounts;\n try {\n counts = await writeArchive(plan, warc, WARC_NAME, async (record) => {\n await index.add(cdxjLine(record, WARC_NAME));\n if (record.page) {\n const page = JSON.stringify({ id: record.capture, url: record.url, ts: record.date });\n await pages.add(`${cacheKeyOf(record.url)}\\t${record.date}\\t${page}`);\n }\n });\n } catch (error) {\n await warc.abandon();\n throw error;\n }\n const archive = await warc.close();\n\n const indexFile = await TalliedFile.create(join(parts, \"index.cdxj\"));\n try {\n await writeLines(indexFile, index.sorted());\n } catch (error) {\n await indexFile.abandon();\n throw error;\n }\n const indexFacts = await indexFile.close();\n\n const pagesFile = await TalliedFile.create(join(parts, \"pages.jsonl\"));\n let pageCount: number;\n try {\n await pagesFile.write(Buffer.from(`${JSON.stringify(PAGES_HEADER)}\\n`));\n pageCount = await writeLines(pagesFile, latestOf(pages.sorted()));\n } catch (error) {\n await pagesFile.abandon();\n throw error;\n }\n const pagesFacts = await pagesFile.close();\n\n const datapackage = Buffer.from(\n JSON.stringify(\n {\n profile: \"data-package\",\n wacz_version: WACZ_VERSION,\n software: `polite-crawler ${VERSION}`,\n created: created.toISOString().replace(/\\.\\d{3}Z$/, \"Z\"),\n title: \"polite-crawler export\",\n resources: [\n resourceOf(`archive/${WARC_NAME}`, archive),\n resourceOf(\"indexes/index.cdxj\", indexFacts),\n resourceOf(\"pages/pages.jsonl\", pagesFacts),\n ],\n },\n null,\n 2,\n ),\n \"utf8\",\n );\n const digest = Buffer.from(\n JSON.stringify(\n {\n path: \"datapackage.json\",\n hash: `sha256:${createHash(\"sha256\").update(datapackage).digest(\"hex\")}`,\n },\n null,\n 2,\n ),\n \"utf8\",\n );\n\n const deflated = async (name: string, facts: Tallied): Promise<ZipMember> => {\n const file = `${facts.path}.deflate`;\n return {\n name,\n method: 8,\n crc: facts.crc,\n size: facts.size,\n compressedSize: await deflateFile(facts.path, file),\n file,\n };\n };\n const members: ZipMember[] = [\n {\n name: `archive/${WARC_NAME}`,\n method: 0,\n crc: archive.crc,\n size: archive.size,\n compressedSize: archive.size,\n file: archive.path,\n },\n await deflated(\"indexes/index.cdxj\", indexFacts),\n await deflated(\"pages/pages.jsonl\", pagesFacts),\n memberOf(\"datapackage.json\", datapackage),\n memberOf(\"datapackage-digest.json\", digest),\n ];\n let bytes: number;\n try {\n bytes = await writeZip(temporary, members, { date: created });\n await rename(temporary, target);\n } catch (error) {\n await rm(temporary, { force: true }).catch(() => undefined);\n throw error;\n }\n return { format: \"wacz\", out: target, bytes, pages: pageCount, ...counts };\n } finally {\n await rm(parts, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });\n }\n};\n"],"mappings":";;;;;;;;;AAIA,MAAMA,YAAU;;AAGhB,MAAM,WAAW,GAAW,MAAsB,OAAO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C3C,WAAW,qBAAqB,UAAU;GAC5C;EACF,GACA,MACA,CACF,GACA,MACF;EACA,MAAM,SAAS,OAAO,KACpB,KAAK,UACH;GACE,MAAM;GACN,MAAM,UAAU,WAAW,QAAQ,CAAC,CAAC,OAAO,WAAW,CAAC,CAAC,OAAO,KAAK;EACvE,GACA,MACA,CACF,GACA,MACF;EAEA,MAAM,WAAW,OAAO,MAAc,UAAuC;GAC3E,MAAM,OAAO,GAAG,MAAM,KAAK;GAC3B,OAAO;IACL;IACA,QAAQ;IACR,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,gBAAgB,MAAM,YAAY,MAAM,MAAM,IAAI;IAClD;GACF;EACF;EACA,MAAM,UAAuB;GAC3B;IACE,MAAM,WAAW;IACjB,QAAQ;IACR,KAAK,QAAQ;IACb,MAAM,QAAQ;IACd,gBAAgB,QAAQ;IACxB,MAAM,QAAQ;GAChB;GACA,MAAM,SAAS,sBAAsB,UAAU;GAC/C,MAAM,SAAS,qBAAqB,UAAU;GAC9C,SAAS,oBAAoB,WAAW;GACxC,SAAS,2BAA2B,MAAM;EAC5C;EACA,IAAI;EACJ,IAAI;GACF,QAAQ,MAAM,SAAS,WAAW,SAAS,EAAE,MAAM,QAAQ,CAAC;GAC5D,MAAM,OAAO,WAAW,MAAM;EAChC,SAAS,OAAO;GACd,MAAM,GAAG,WAAW,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,YAAY,KAAA,CAAS;GAC1D,MAAM;EACR;EACA,OAAO;GAAE,QAAQ;GAAQ,KAAK;GAAQ;GAAO,OAAO;GAAW,GAAG;EAAO;CAC3E,UAAU;EACR,MAAM,GAAG,OAAO;GAAE,WAAW;GAAM,OAAO;GAAM,YAAY;GAAG,YAAY;EAAI,CAAC;CAClF;AACF"}
|
|
1
|
+
{"version":3,"file":"wacz-DjgklRod.mjs","names":["NEWLINE"],"sources":["../src/sorter.ts","../src/wacz.ts"],"sourcesContent":["import { createReadStream } from \"node:fs\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nconst NEWLINE = 0x0a;\n\n/** This function compares two lines by their bytes. */\nconst byBytes = (a: Buffer, b: Buffer): number => Buffer.compare(a, b);\n\n/** This function reads a file line by line, as bytes. A line holds no line break. */\nasync function* linesOf(path: string): AsyncGenerator<Buffer> {\n let rest: Buffer | undefined;\n for await (const chunk of createReadStream(path) as AsyncIterable<Buffer>) {\n const data = rest === undefined ? chunk : Buffer.concat([rest, chunk]);\n rest = undefined;\n let start = 0;\n for (;;) {\n const end = data.indexOf(NEWLINE, start);\n if (end === -1) break;\n yield data.subarray(start, end);\n start = end + 1;\n }\n if (start < data.length) rest = Buffer.from(data.subarray(start));\n }\n if (rest !== undefined && rest.length > 0) yield rest;\n}\n\n/**\n * A line sorter sorts lines of text in the sequence of their UTF-8 bytes (the sequence of\n * `LC_ALL=C sort`). It keeps no more than `limit` bytes of lines in memory. When it has more, it\n * writes them to a sorted file in `dir`. At the end it merges the files. Thus its memory does not\n * grow with the count of lines. The WACZ export sorts its index and its page list with it.\n *\n * A line must not hold a line break.\n */\nexport class LineSorter {\n private lines: Buffer[] = [];\n private bytes = 0;\n private readonly runs: string[] = [];\n\n constructor(\n private readonly dir: string,\n private readonly limit: number = 8 * 1024 * 1024,\n ) {}\n\n /** This value is the count of sorted files that the sorter wrote. */\n get files(): number {\n return this.runs.length;\n }\n\n async add(line: string): Promise<void> {\n const bytes = Buffer.from(line, \"utf8\");\n if (bytes.includes(NEWLINE)) throw new Error(\"a line to sort holds a line break\");\n this.lines.push(bytes);\n // each line also costs an object in memory, so the count adds a little for each line\n this.bytes += bytes.length + 64;\n if (this.bytes >= this.limit) await this.spill();\n }\n\n private async spill(): Promise<void> {\n if (this.lines.length === 0) return;\n this.lines.sort(byBytes);\n await mkdir(this.dir, { recursive: true });\n const path = join(this.dir, `${String(this.runs.length)}.lines`);\n const parts: Buffer[] = [];\n const newline = Buffer.from([NEWLINE]);\n for (const line of this.lines) parts.push(line, newline);\n await writeFile(path, Buffer.concat(parts), { mode: 0o600 });\n this.runs.push(path);\n this.lines = [];\n this.bytes = 0;\n }\n\n /** This method gives each line in the sorted sequence. Use it one time, after the last `add`. */\n async *sorted(): AsyncGenerator<Buffer> {\n if (this.runs.length === 0) {\n const lines = this.lines.sort(byBytes);\n this.lines = [];\n yield* lines;\n return;\n }\n await this.spill();\n const readers = this.runs.map((path) => linesOf(path)[Symbol.asyncIterator]());\n const heads: Array<Buffer | undefined> = [];\n for (const reader of readers) heads.push((await reader.next()).value ?? undefined);\n for (;;) {\n let pick = -1;\n for (const [at, head] of heads.entries()) {\n if (head !== undefined && (pick === -1 || Buffer.compare(head, heads[pick]!) < 0))\n pick = at;\n }\n if (pick === -1) return;\n yield heads[pick]!;\n heads[pick] = (await readers[pick]!.next()).value ?? undefined;\n }\n }\n}\n","import { createHash } from \"node:crypto\";\nimport { mkdir, rename, rm } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport { LineSorter } from \"./sorter.ts\";\nimport { cacheKeyOf } from \"./urls.ts\";\nimport { VERSION } from \"./version.ts\";\nimport type { ArchiveCounts, ArchiveOptions, ArchiveSource } from \"./warc.ts\";\nimport { cdxjLine, outputOf, planArchive, writeArchive } from \"./warc.ts\";\nimport type { Tallied, ZipMember } from \"./zip.ts\";\nimport { TalliedFile, deflateFile, memberOf, writeZip } from \"./zip.ts\";\n\n/*\n * This module writes a WACZ 1.1.1 file: a ZIP with the WARC file, a sorted CDXJ index, a page list\n * and the data package with the SHA-256 of each part. Replay tools (ReplayWeb.page, pywb) open it.\n */\n\n/** This is the version of the WACZ specification that the export follows. */\nconst WACZ_VERSION = \"1.1.1\";\nconst WARC_NAME = \"data.warc.gz\";\nconst NEWLINE = Buffer.from(\"\\n\");\nconst TAB = 0x09;\nconst PAGES_HEADER = { format: \"json-pages-1.0\", id: \"pages\", title: \"All Pages\" };\n\n/** This is the result of `exportWacz`. */\nexport interface WaczResult extends ArchiveCounts {\n readonly format: \"wacz\";\n /** This value is the absolute path of the archive. */\n readonly out: string;\n readonly bytes: number;\n /** This value is the count of pages in `pages/pages.jsonl`: one for each document. */\n readonly pages: number;\n}\n\n/** This function writes lines to a file in batches of approximately 64 KiB. It gives the count of lines. */\nconst writeLines = async (file: TalliedFile, lines: AsyncIterable<Uint8Array>): Promise<number> => {\n let batch: Uint8Array[] = [];\n let size = 0;\n let count = 0;\n for await (const line of lines) {\n batch.push(line, NEWLINE);\n size += line.length + 1;\n count += 1;\n if (size >= 65_536) {\n await file.write(Buffer.concat(batch));\n batch = [];\n size = 0;\n }\n }\n if (batch.length > 0) await file.write(Buffer.concat(batch));\n return count;\n};\n\n/**\n * This function keeps the last line of each document. Each line is the key of the document, a tab,\n * the time, a tab and the JSON of the page. The sorter gives the lines of one key together, the\n * oldest first.\n */\nasync function* latestOf(lines: AsyncIterable<Buffer>): AsyncGenerator<Buffer> {\n let held: Buffer | undefined;\n let heldKey: Buffer | undefined;\n for await (const line of lines) {\n const key = line.subarray(0, line.indexOf(TAB));\n if (held !== undefined && heldKey !== undefined && !key.equals(heldKey)) {\n yield held.subarray(held.indexOf(TAB, heldKey.length + 1) + 1);\n }\n held = line;\n heldKey = key;\n }\n if (held !== undefined && heldKey !== undefined)\n yield held.subarray(held.indexOf(TAB, heldKey.length + 1) + 1);\n}\n\nconst resourceOf = (\n path: string,\n facts: Tallied,\n): {\n readonly name: string;\n readonly path: string;\n readonly hash: string;\n readonly bytes: number;\n} => ({\n name: basename(path).toLowerCase(),\n path,\n hash: `sha256:${facts.sha256}`,\n bytes: facts.size,\n});\n\n/**\n * This function writes the captures of a store as a WACZ 1.1.1 file. The ZIP holds these parts:\n *\n * - `archive/data.warc.gz`: the WARC file of `exportWarc`, stored with no more compression, so a\n * replay tool reads a record at its offset.\n * - `indexes/index.cdxj`: the index of the `response` and `revisit` records, sorted by SURT key.\n * - `pages/pages.jsonl`: one page for each document, at its latest capture.\n * - `datapackage.json` and `datapackage-digest.json`: the SHA-256 of each part, and of the package.\n *\n * The index and the page list are sorted on the disk, so the memory does not grow with the store.\n * The export writes temporary files beside `out` and removes them at the end.\n */\nexport const exportWacz = async (\n source: ArchiveSource,\n options: ArchiveOptions,\n): Promise<WaczResult> => {\n const plan = planArchive(source, options);\n const { target, temporary } = outputOf(options);\n const parts = `${temporary}.parts`;\n await mkdir(parts, { recursive: true, mode: 0o700 });\n try {\n const created = new Date();\n const warc = await TalliedFile.create(join(parts, WARC_NAME));\n const index = new LineSorter(join(parts, \"index\"));\n const pages = new LineSorter(join(parts, \"pages\"));\n let counts: ArchiveCounts;\n try {\n counts = await writeArchive(plan, warc, WARC_NAME, async (record) => {\n await index.add(cdxjLine(record, WARC_NAME));\n if (record.page) {\n const page = JSON.stringify({ id: record.capture, url: record.url, ts: record.date });\n await pages.add(`${cacheKeyOf(record.url)}\\t${record.date}\\t${page}`);\n }\n });\n } catch (error) {\n await warc.abandon();\n throw error;\n }\n const archive = await warc.close();\n\n const indexFile = await TalliedFile.create(join(parts, \"index.cdxj\"));\n try {\n await writeLines(indexFile, index.sorted());\n } catch (error) {\n await indexFile.abandon();\n throw error;\n }\n const indexFacts = await indexFile.close();\n\n const pagesFile = await TalliedFile.create(join(parts, \"pages.jsonl\"));\n let pageCount: number;\n try {\n await pagesFile.write(Buffer.from(`${JSON.stringify(PAGES_HEADER)}\\n`));\n pageCount = await writeLines(pagesFile, latestOf(pages.sorted()));\n } catch (error) {\n await pagesFile.abandon();\n throw error;\n }\n const pagesFacts = await pagesFile.close();\n\n const datapackage = Buffer.from(\n JSON.stringify(\n {\n profile: \"data-package\",\n wacz_version: WACZ_VERSION,\n software: `polite-crawler ${VERSION}`,\n created: created.toISOString().replace(/\\.\\d{3}Z$/, \"Z\"),\n title: \"polite-crawler export\",\n resources: [\n resourceOf(`archive/${WARC_NAME}`, archive),\n resourceOf(\"indexes/index.cdxj\", indexFacts),\n resourceOf(\"pages/pages.jsonl\", pagesFacts),\n ],\n },\n null,\n 2,\n ),\n \"utf8\",\n );\n const digest = Buffer.from(\n JSON.stringify(\n {\n path: \"datapackage.json\",\n hash: `sha256:${createHash(\"sha256\").update(datapackage).digest(\"hex\")}`,\n },\n null,\n 2,\n ),\n \"utf8\",\n );\n\n const deflated = async (name: string, facts: Tallied): Promise<ZipMember> => {\n const file = `${facts.path}.deflate`;\n return {\n name,\n method: 8,\n crc: facts.crc,\n size: facts.size,\n compressedSize: await deflateFile(facts.path, file),\n file,\n };\n };\n const members: ZipMember[] = [\n {\n name: `archive/${WARC_NAME}`,\n method: 0,\n crc: archive.crc,\n size: archive.size,\n compressedSize: archive.size,\n file: archive.path,\n },\n await deflated(\"indexes/index.cdxj\", indexFacts),\n await deflated(\"pages/pages.jsonl\", pagesFacts),\n memberOf(\"datapackage.json\", datapackage),\n memberOf(\"datapackage-digest.json\", digest),\n ];\n let bytes: number;\n try {\n bytes = await writeZip(temporary, members, { date: created });\n await rename(temporary, target);\n } catch (error) {\n await rm(temporary, { force: true }).catch(() => undefined);\n throw error;\n }\n return { format: \"wacz\", out: target, bytes, pages: pageCount, ...counts };\n } finally {\n await rm(parts, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });\n }\n};\n"],"mappings":";;;;;;;;;AAIA,MAAMA,YAAU;;AAGhB,MAAM,WAAW,GAAW,MAAsB,OAAO,QAAQ,GAAG,CAAC;;AAGrE,gBAAgB,QAAQ,MAAsC;CAC5D,IAAI;CACJ,WAAW,MAAM,SAAS,iBAAiB,IAAI,GAA4B;EACzE,MAAM,OAAO,SAAS,KAAA,IAAY,QAAQ,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC;EACrE,OAAO,KAAA;EACP,IAAI,QAAQ;EACZ,SAAS;GACP,MAAM,MAAM,KAAK,QAAQA,WAAS,KAAK;GACvC,IAAI,QAAQ,IAAI;GAChB,MAAM,KAAK,SAAS,OAAO,GAAG;GAC9B,QAAQ,MAAM;EAChB;EACA,IAAI,QAAQ,KAAK,QAAQ,OAAO,OAAO,KAAK,KAAK,SAAS,KAAK,CAAC;CAClE;CAC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AAM,WAAW;IACjB,QAAQ;IACR,KAAK,QAAQ;IACb,MAAM,QAAQ;IACd,gBAAgB,QAAQ;IACxB,MAAM,QAAQ;GAChB;GACA,MAAM,SAAS,sBAAsB,UAAU;GAC/C,MAAM,SAAS,qBAAqB,UAAU;GAC9C,SAAS,oBAAoB,WAAW;GACxC,SAAS,2BAA2B,MAAM;EAC5C;EACA,IAAI;EACJ,IAAI;GACF,QAAQ,MAAM,SAAS,WAAW,SAAS,EAAE,MAAM,QAAQ,CAAC;GAC5D,MAAM,OAAO,WAAW,MAAM;EAChC,SAAS,OAAO;GACd,MAAM,GAAG,WAAW,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,YAAY,KAAA,CAAS;GAC1D,MAAM;EACR;EACA,OAAO;GAAE,QAAQ;GAAQ,KAAK;GAAQ;GAAO,OAAO;GAAW,GAAG;EAAO;CAC3E,UAAU;EACR,MAAM,GAAG,OAAO;GAAE,WAAW;GAAM,OAAO;GAAM,YAAY;GAAG,YAAY;EAAI,CAAC;CAClF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
|
|
2
2
|
import { n as FileBlobStore, t as CaptureLog } from "./log-CB5bADmd.mjs";
|
|
3
|
-
import { r as VERSION, t as BOT_PAGE } from "./version-
|
|
3
|
+
import { r as VERSION, t as BOT_PAGE } from "./version-DxUGcHQr.mjs";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { open, rename, rm, stat } from "node:fs/promises";
|
|
6
6
|
import { basename, join, resolve } from "node:path";
|
|
@@ -715,4 +715,4 @@ const exportWarc = async (source, options) => {
|
|
|
715
715
|
};
|
|
716
716
|
export { warc_exports as a, deflateFile as c, planArchive as i, memberOf as l, exportWarc as n, writeArchive as o, outputOf as r, TalliedFile as s, cdxjLine as t, writeZip as u };
|
|
717
717
|
|
|
718
|
-
//# sourceMappingURL=warc-
|
|
718
|
+
//# sourceMappingURL=warc-CgkNdXyG.mjs.map
|