bagit-node 0.0.0-stage → 1.0.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 +21 -0
- package/NOTICE +6 -0
- package/README.md +228 -2
- package/dist/cjs/bag.d.ts +59 -0
- package/dist/cjs/bag.d.ts.map +1 -0
- package/dist/cjs/bag.js +329 -0
- package/dist/cjs/bag.js.map +1 -0
- package/dist/cjs/errors.d.ts +32 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +60 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +29 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/util.d.ts +39 -0
- package/dist/cjs/util.d.ts.map +1 -0
- package/dist/cjs/util.js +355 -0
- package/dist/cjs/util.js.map +1 -0
- package/dist/cjs/zip.d.ts +47 -0
- package/dist/cjs/zip.d.ts.map +1 -0
- package/dist/cjs/zip.js +336 -0
- package/dist/cjs/zip.js.map +1 -0
- package/dist/esm/bag.d.ts +59 -0
- package/dist/esm/bag.d.ts.map +1 -0
- package/dist/esm/bag.js +322 -0
- package/dist/esm/bag.js.map +1 -0
- package/dist/esm/errors.d.ts +32 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +50 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +29 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util.d.ts +39 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/util.js +326 -0
- package/dist/esm/util.js.map +1 -0
- package/dist/esm/zip.d.ts +47 -0
- package/dist/esm/zip.d.ts.map +1 -0
- package/dist/esm/zip.js +330 -0
- package/dist/esm/zip.js.map +1 -0
- package/package.json +46 -4
package/dist/esm/util.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createReadStream, existsSync, readdirSync, realpathSync, statSync, constants, accessSync } from 'node:fs';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve, sep, win32 } from 'node:path';
|
|
5
|
+
import { BagError, BagValidationError, FileNormalizationConflict } from './errors.js';
|
|
6
|
+
export const VERSION = '1.0.0';
|
|
7
|
+
export const DEFAULT_CHECKSUMS = Object.freeze(['sha256', 'sha512']);
|
|
8
|
+
export const HASH_BLOCK_SIZE = 512 * 1024;
|
|
9
|
+
export const BAG_DECLARATION = 'BagIt-Version: 1.0\nTag-File-Character-Encoding: UTF-8\n';
|
|
10
|
+
export const STANDARD_BAG_INFO_HEADERS = Object.freeze([
|
|
11
|
+
'Source-Organization', 'Organization-Address', 'Contact-Name', 'Contact-Phone', 'Contact-Email',
|
|
12
|
+
'External-Description', 'External-Identifier', 'Bag-Size', 'Bag-Group-Identifier', 'Bag-Count',
|
|
13
|
+
'Internal-Sender-Identifier', 'Internal-Sender-Description', 'BagIt-Profile-Identifier',
|
|
14
|
+
]);
|
|
15
|
+
// Python's guaranteed fixed-length algorithms, mapped to OpenSSL names where necessary.
|
|
16
|
+
const HASH_NAMES = {
|
|
17
|
+
blake2b: 'blake2b512', blake2s: 'blake2s256',
|
|
18
|
+
sha3_224: 'sha3-224', sha3_256: 'sha3-256', sha3_384: 'sha3-384', sha3_512: 'sha3-512',
|
|
19
|
+
};
|
|
20
|
+
export const CHECKSUM_ALGOS = Object.freeze([
|
|
21
|
+
'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
|
|
22
|
+
'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'blake2b', 'blake2s',
|
|
23
|
+
]);
|
|
24
|
+
export function getHashers(algorithms) {
|
|
25
|
+
const result = Object.create(null);
|
|
26
|
+
for (const alg of algorithms) {
|
|
27
|
+
if (!CHECKSUM_ALGOS.includes(alg))
|
|
28
|
+
continue;
|
|
29
|
+
try {
|
|
30
|
+
result[alg] = createHash(HASH_NAMES[alg] ?? alg);
|
|
31
|
+
}
|
|
32
|
+
catch { /* unavailable in this OpenSSL build */ }
|
|
33
|
+
}
|
|
34
|
+
if (!Object.keys(result).length)
|
|
35
|
+
throw new BagError('Unable to continue: no supported checksum algorithms were requested');
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
export function algorithmsFor(algorithms = DEFAULT_CHECKSUMS) {
|
|
39
|
+
return Object.keys(getHashers(algorithms));
|
|
40
|
+
}
|
|
41
|
+
export function digestBytes(bytes, algorithms) {
|
|
42
|
+
return Object.fromEntries(Object.entries(getHashers(algorithms)).map(([a, h]) => [a, h.update(bytes).digest('hex')]));
|
|
43
|
+
}
|
|
44
|
+
export async function hashFile(path, algorithms, signal) {
|
|
45
|
+
const hashers = getHashers(algorithms);
|
|
46
|
+
let bytes = 0n;
|
|
47
|
+
try {
|
|
48
|
+
for await (const block of createReadStream(path, { highWaterMark: HASH_BLOCK_SIZE, signal })) {
|
|
49
|
+
bytes += BigInt(block.length);
|
|
50
|
+
for (const hash of Object.values(hashers))
|
|
51
|
+
hash.update(block);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
signal?.throwIfAborted();
|
|
56
|
+
throw new BagValidationError(`Could not read ${path}: ${String(error)}`, [], { cause: error });
|
|
57
|
+
}
|
|
58
|
+
return { hashes: Object.fromEntries(Object.entries(hashers).map(([a, h]) => [a, h.digest('hex')])), bytes };
|
|
59
|
+
}
|
|
60
|
+
export async function generateManifestLines(filename, algorithms = DEFAULT_CHECKSUMS, signal) {
|
|
61
|
+
const { hashes, bytes } = await hashFile(filename, algorithms, signal);
|
|
62
|
+
return Object.entries(hashes).map(([algorithm, digest]) => [algorithm, digest, filename, bytes]);
|
|
63
|
+
}
|
|
64
|
+
export const normalizeUnicode = (s) => s.normalize('NFC');
|
|
65
|
+
export function buildUnicodeNormalizedLookupDict(filenames) {
|
|
66
|
+
const result = Object.create(null);
|
|
67
|
+
for (const filename of filenames) {
|
|
68
|
+
const normalized = normalizeUnicode(filename);
|
|
69
|
+
if (Object.hasOwn(result, normalized))
|
|
70
|
+
throw new FileNormalizationConflict(filename, result[normalized]);
|
|
71
|
+
result[normalized] = filename;
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
export const encodeFilename = (s) => s.replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
76
|
+
export const decodeFilename = (s) => s.replace(/%0d/gi, '\r').replace(/%0a/gi, '\n');
|
|
77
|
+
export const posixPath = (s) => s.split(sep).join('/');
|
|
78
|
+
export const isFile = (p) => { try {
|
|
79
|
+
return statSync(p).isFile();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
} };
|
|
84
|
+
export const isDirectory = (p) => { try {
|
|
85
|
+
return statSync(p).isDirectory();
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
} };
|
|
90
|
+
/** Match os.walk: sorted files at each level, then sorted directories; do not follow directory symlinks. */
|
|
91
|
+
export function* walkFiles(root, prefix = '') {
|
|
92
|
+
if (!isDirectory(root))
|
|
93
|
+
return;
|
|
94
|
+
const entries = readdirSync(root, { withFileTypes: true }).sort((a, b) => compareNames(a.name, b.name));
|
|
95
|
+
for (const e of entries) {
|
|
96
|
+
const p = join(root, e.name);
|
|
97
|
+
if (e.isFile() || (e.isSymbolicLink() && !isDirectory(p)))
|
|
98
|
+
yield prefix + e.name;
|
|
99
|
+
}
|
|
100
|
+
for (const e of entries)
|
|
101
|
+
if (e.isDirectory())
|
|
102
|
+
yield* walkFiles(join(root, e.name), `${prefix}${e.name}/`);
|
|
103
|
+
}
|
|
104
|
+
export function compareNames(a, b) {
|
|
105
|
+
// Python sorts Unicode code points, whereas JavaScript's default sort uses UTF-16 code units.
|
|
106
|
+
const ac = Array.from(a, c => c.codePointAt(0));
|
|
107
|
+
const bc = Array.from(b, c => c.codePointAt(0));
|
|
108
|
+
for (let i = 0; i < Math.min(ac.length, bc.length); i++)
|
|
109
|
+
if (ac[i] !== bc[i])
|
|
110
|
+
return ac[i] - bc[i];
|
|
111
|
+
return ac.length - bc.length;
|
|
112
|
+
}
|
|
113
|
+
function canonicalMissingPath(path) {
|
|
114
|
+
if (existsSync(path))
|
|
115
|
+
return realpathSync(path);
|
|
116
|
+
const parent = dirname(path);
|
|
117
|
+
if (parent === path)
|
|
118
|
+
return path;
|
|
119
|
+
// realpath still detects symlinks in the existing part of an absent fetch target.
|
|
120
|
+
return join(canonicalMissingPath(parent), relative(parent, path));
|
|
121
|
+
}
|
|
122
|
+
export function pathIsDangerous(root, filename) {
|
|
123
|
+
if (!filename || filename.includes('\0') || isAbsolute(filename) || win32.isAbsolute(filename) || filename.startsWith('~'))
|
|
124
|
+
return true;
|
|
125
|
+
const actual = canonicalMissingPath(resolve(root, filename));
|
|
126
|
+
const rel = relative(realpathSync(root), actual);
|
|
127
|
+
return rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel);
|
|
128
|
+
}
|
|
129
|
+
export function assertSafePath(root, filename, context = 'manifest') {
|
|
130
|
+
if (pathIsDangerous(root, filename))
|
|
131
|
+
throw new BagError(`Path "${filename}" in ${context} is unsafe`);
|
|
132
|
+
}
|
|
133
|
+
export function decodeText(bytes, encoding = 'utf-8') {
|
|
134
|
+
let label = encodingLabel(encoding);
|
|
135
|
+
if (label === 'utf-16') {
|
|
136
|
+
if (bytes[0] === 0xfe && bytes[1] === 0xff)
|
|
137
|
+
label = 'utf-16be';
|
|
138
|
+
else if (bytes[0] === 0xff && bytes[1] === 0xfe)
|
|
139
|
+
label = 'utf-16le';
|
|
140
|
+
else if (bytes.length)
|
|
141
|
+
throw new BagValidationError('UTF-16 tag file must begin with a byte-order mark');
|
|
142
|
+
}
|
|
143
|
+
if (label === 'utf-8-sig')
|
|
144
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
145
|
+
if (label === 'ascii' || label === 'us-ascii') {
|
|
146
|
+
if (bytes.some(b => b > 127))
|
|
147
|
+
throw new BagValidationError('Non-ASCII byte in ASCII tag file');
|
|
148
|
+
return Buffer.from(bytes).toString('ascii');
|
|
149
|
+
}
|
|
150
|
+
// TextDecoder maps ISO-8859-1 to Windows-1252; Python uses the actual ISO mapping.
|
|
151
|
+
if (['latin-1', 'latin1', 'iso-8859-1'].includes(label))
|
|
152
|
+
return Buffer.from(bytes).toString('latin1');
|
|
153
|
+
try {
|
|
154
|
+
return new TextDecoder(label, { fatal: true }).decode(bytes);
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
throw new BagValidationError(`Cannot decode tag file as ${encoding}`, [], { cause: e });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export function checkEncoding(encoding) {
|
|
161
|
+
const label = encodingLabel(encoding);
|
|
162
|
+
if (['utf-8-sig', 'latin-1'].includes(label))
|
|
163
|
+
return;
|
|
164
|
+
try {
|
|
165
|
+
new TextDecoder(label);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
throw new BagValidationError(`Unsupported encoding: ${encoding}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export function encodeText(text, encoding = 'utf-8') {
|
|
172
|
+
const label = encodingLabel(encoding);
|
|
173
|
+
if (['utf-8', 'utf8', 'utf-8-sig'].includes(label)) {
|
|
174
|
+
const bytes = Buffer.from(text, 'utf8');
|
|
175
|
+
return label === 'utf-8-sig' ? Buffer.concat([Buffer.from([0xef, 0xbb, 0xbf]), bytes]) : bytes;
|
|
176
|
+
}
|
|
177
|
+
if (['utf-16', 'utf-16le', 'utf-16-le', 'utf16le'].includes(label)) {
|
|
178
|
+
const bytes = Buffer.from(text, 'utf16le');
|
|
179
|
+
return label === 'utf-16' ? Buffer.concat([Buffer.from([0xff, 0xfe]), bytes]) : bytes;
|
|
180
|
+
}
|
|
181
|
+
if (['utf-16be', 'utf-16-be'].includes(label))
|
|
182
|
+
return Buffer.from(text, 'utf16le').swap16();
|
|
183
|
+
const table = new Map();
|
|
184
|
+
for (let b = 0; b < 256; b++) {
|
|
185
|
+
try {
|
|
186
|
+
const c = decodeText(Uint8Array.of(b), encoding);
|
|
187
|
+
if (c.length === 1 && !table.has(c))
|
|
188
|
+
table.set(c, b);
|
|
189
|
+
}
|
|
190
|
+
catch { /* invalid single byte */ }
|
|
191
|
+
}
|
|
192
|
+
const bytes = [];
|
|
193
|
+
for (const c of text) {
|
|
194
|
+
const b = table.get(c);
|
|
195
|
+
if (b === undefined)
|
|
196
|
+
throw new BagError(`Cannot encode character ${JSON.stringify(c)} as ${encoding}`);
|
|
197
|
+
bytes.push(b);
|
|
198
|
+
}
|
|
199
|
+
return Buffer.from(bytes);
|
|
200
|
+
}
|
|
201
|
+
function encodingLabel(encoding) {
|
|
202
|
+
const label = encoding.toLowerCase().replace(/_/g, '-');
|
|
203
|
+
return { utf8: 'utf-8', utf16: 'utf-16', utf16le: 'utf-16le', utf16be: 'utf-16be', 'utf-16-le': 'utf-16le', 'utf-16-be': 'utf-16be' }[label] ?? label;
|
|
204
|
+
}
|
|
205
|
+
export function parseTagFile(text, filename = 'tag file') {
|
|
206
|
+
const result = Object.create(null);
|
|
207
|
+
let key;
|
|
208
|
+
let value = '';
|
|
209
|
+
const emit = () => {
|
|
210
|
+
if (!key)
|
|
211
|
+
return;
|
|
212
|
+
const v = value.trim();
|
|
213
|
+
const prev = result[key];
|
|
214
|
+
result[key] = prev === undefined ? v : Array.isArray(prev) ? [...prev, v] : [prev, v];
|
|
215
|
+
};
|
|
216
|
+
for (const line of text.replace(/\r\n?/g, '\n').match(/[^\n]*\n|[^\n]+$/g) ?? []) {
|
|
217
|
+
if (!line.trim())
|
|
218
|
+
continue;
|
|
219
|
+
if (/^\s/.test(line) && key !== undefined)
|
|
220
|
+
value += line;
|
|
221
|
+
else {
|
|
222
|
+
emit();
|
|
223
|
+
const colon = line.indexOf(':');
|
|
224
|
+
if (colon < 0)
|
|
225
|
+
throw new BagValidationError(`${filename} contains invalid tag: ${line.trim()}`);
|
|
226
|
+
key = line.slice(0, colon).trim();
|
|
227
|
+
value = line.slice(colon + 1);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
emit();
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
export function serializeTagFile(info) {
|
|
234
|
+
let result = '';
|
|
235
|
+
for (const key of Object.keys(info).sort(compareNames)) {
|
|
236
|
+
if (!key || /[\r\n:]/.test(key))
|
|
237
|
+
throw new BagError(`Invalid metadata field name: ${key}`);
|
|
238
|
+
const values = Array.isArray(info[key]) ? info[key] : [info[key]];
|
|
239
|
+
for (const value of values)
|
|
240
|
+
result += `${key}: ${String(value).replace(/[\r\n]/g, '')}\n`;
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
export function makeBagInfo(info, bytes, files) {
|
|
245
|
+
const date = new Date();
|
|
246
|
+
const today = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
247
|
+
return parseTagFile(serializeTagFile({
|
|
248
|
+
'Bagging-Date': today,
|
|
249
|
+
'Bag-Software-Agent': `bagit-node v${VERSION}`,
|
|
250
|
+
...info,
|
|
251
|
+
'Payload-Oxum': `${bytes}.${files}`,
|
|
252
|
+
}));
|
|
253
|
+
}
|
|
254
|
+
export async function loadTagFile(path, encoding = 'utf-8') {
|
|
255
|
+
return parseTagFile(decodeText(await readFile(path), encoding), path);
|
|
256
|
+
}
|
|
257
|
+
export function checkPermissions(root, saving = false) {
|
|
258
|
+
try {
|
|
259
|
+
accessSync(root, constants.R_OK | constants.W_OK | constants.X_OK);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
throw new BagError(saving ? `Cannot save bag to non-existent or inaccessible directory ${root}` : 'Missing permissions to move all files and directories');
|
|
263
|
+
}
|
|
264
|
+
const dirs = [root];
|
|
265
|
+
const files = [];
|
|
266
|
+
// Finish the write check before reporting unreadable descendants, matching Python.
|
|
267
|
+
for (let i = 0; i < dirs.length; i++) {
|
|
268
|
+
const dir = dirs[i];
|
|
269
|
+
try {
|
|
270
|
+
accessSync(dir, constants.W_OK);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
throw new BagError('Missing permissions to move all files and directories');
|
|
274
|
+
}
|
|
275
|
+
let entries;
|
|
276
|
+
try {
|
|
277
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
throw new BagError('Read permissions are required to calculate file fixities');
|
|
281
|
+
}
|
|
282
|
+
for (const e of entries) {
|
|
283
|
+
if (e.isDirectory())
|
|
284
|
+
dirs.push(join(dir, e.name));
|
|
285
|
+
else
|
|
286
|
+
files.push(join(dir, e.name));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const p of [...dirs, ...files]) {
|
|
290
|
+
try {
|
|
291
|
+
accessSync(p, constants.R_OK);
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
throw new BagError('Read permissions are required to calculate file fixities');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
export function checkConcurrency(concurrency = 1) {
|
|
299
|
+
if (!Number.isSafeInteger(concurrency) || concurrency < 1)
|
|
300
|
+
throw new RangeError('concurrency must be a positive integer');
|
|
301
|
+
return concurrency;
|
|
302
|
+
}
|
|
303
|
+
export async function mapConcurrent(items, concurrency, fn) {
|
|
304
|
+
const result = new Array(items.length);
|
|
305
|
+
let next = 0;
|
|
306
|
+
let failure;
|
|
307
|
+
let failed = false;
|
|
308
|
+
await Promise.all(Array.from({ length: Math.min(checkConcurrency(concurrency), items.length) }, async () => {
|
|
309
|
+
while (!failed) {
|
|
310
|
+
const i = next++;
|
|
311
|
+
if (i >= items.length)
|
|
312
|
+
return;
|
|
313
|
+
try {
|
|
314
|
+
result[i] = await fn(items[i]);
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
failed = true;
|
|
318
|
+
failure = error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}));
|
|
322
|
+
if (failed)
|
|
323
|
+
throw failure;
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAGtF,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAC/B,MAAM,CAAC,MAAM,iBAAiB,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AACxF,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,GAAG,IAAI,CAAC;AAC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AU,CAAC,wCAAwC,CAAC,CAAC;IAC1H,OAAO,WAAW,CAAC;AACrB,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAO,KAAmB,EAAE,WAAmB,EAAE,EAA4B;IAC9G,MAAM,MAAM,GAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,OAAgB,CAAC;IACrB,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,IAAI,EAAE;QACzG,OAAO,CAAC,MAAM,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC;YACjB,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM;gBAAE,OAAO;YAC9B,IAAI,CAAC;gBAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;YAAC,CAAC;YACxC,OAAO,KAAK,EAAE,CAAC;gBAAC,MAAM,GAAG,IAAI,CAAC;gBAAC,OAAO,GAAG,KAAK,CAAC;YAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC,CAAC;IACJ,IAAI,MAAM;QAAE,MAAM,OAAO,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { createHash, type Hash } from 'node:crypto';\nimport { createReadStream, existsSync, readdirSync, realpathSync, statSync, constants, accessSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve, sep, win32 } from 'node:path';\nimport { BagError, BagValidationError, FileNormalizationConflict } from './errors.js';\nimport type { BagInfo, BagInfoInput, Checksums } from './types.js';\n\nexport const VERSION = '1.0.0';\nexport const DEFAULT_CHECKSUMS: readonly string[] = Object.freeze(['sha256', 'sha512']);\nexport const HASH_BLOCK_SIZE = 512 * 1024;\nexport const BAG_DECLARATION = 'BagIt-Version: 1.0\\nTag-File-Character-Encoding: UTF-8\\n';\nexport const STANDARD_BAG_INFO_HEADERS: readonly string[] = Object.freeze([\n 'Source-Organization', 'Organization-Address', 'Contact-Name', 'Contact-Phone', 'Contact-Email',\n 'External-Description', 'External-Identifier', 'Bag-Size', 'Bag-Group-Identifier', 'Bag-Count',\n 'Internal-Sender-Identifier', 'Internal-Sender-Description', 'BagIt-Profile-Identifier',\n]);\n// Python's guaranteed fixed-length algorithms, mapped to OpenSSL names where necessary.\nconst HASH_NAMES: Record<string, string> = {\n blake2b: 'blake2b512', blake2s: 'blake2s256',\n sha3_224: 'sha3-224', sha3_256: 'sha3-256', sha3_384: 'sha3-384', sha3_512: 'sha3-512',\n};\nexport const CHECKSUM_ALGOS: readonly string[] = Object.freeze([\n 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',\n 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'blake2b', 'blake2s',\n]);\nexport function getHashers(algorithms: readonly string[]): Record<string, Hash> {\n const result: Record<string, Hash> = Object.create(null);\n for (const alg of algorithms) {\n if (!CHECKSUM_ALGOS.includes(alg)) continue;\n try { result[alg] = createHash(HASH_NAMES[alg] ?? alg); } catch { /* unavailable in this OpenSSL build */ }\n }\n if (!Object.keys(result).length) throw new BagError('Unable to continue: no supported checksum algorithms were requested');\n return result;\n}\nexport function algorithmsFor(algorithms: readonly string[] = DEFAULT_CHECKSUMS): string[] {\n return Object.keys(getHashers(algorithms));\n}\nexport function digestBytes(bytes: Uint8Array, algorithms: readonly string[]): Checksums {\n return Object.fromEntries(Object.entries(getHashers(algorithms)).map(([a, h]) => [a, h.update(bytes).digest('hex')]));\n}\nexport async function hashFile(path: string, algorithms: readonly string[], signal?: AbortSignal): Promise<{ hashes: Checksums; bytes: bigint }> {\n const hashers = getHashers(algorithms);\n let bytes = 0n;\n try {\n for await (const block of createReadStream(path, { highWaterMark: HASH_BLOCK_SIZE, signal })) {\n bytes += BigInt(block.length);\n for (const hash of Object.values(hashers)) hash.update(block);\n }\n } catch (error) {\n signal?.throwIfAborted();\n throw new BagValidationError(`Could not read ${path}: ${String(error)}`, [], { cause: error });\n }\n return { hashes: Object.fromEntries(Object.entries(hashers).map(([a, h]) => [a, h.digest('hex')])), bytes };\n}\nexport async function generateManifestLines(filename: string, algorithms: readonly string[] = DEFAULT_CHECKSUMS, signal?: AbortSignal): Promise<[algorithm: string, digest: string, filename: string, bytes: bigint][]> {\n const { hashes, bytes } = await hashFile(filename, algorithms, signal);\n return Object.entries(hashes).map(([algorithm, digest]) => [algorithm, digest, filename, bytes]);\n}\nexport const normalizeUnicode = (s: string): string => s.normalize('NFC');\nexport function buildUnicodeNormalizedLookupDict(filenames: Iterable<string>): Record<string, string> {\n const result: Record<string, string> = Object.create(null);\n for (const filename of filenames) {\n const normalized = normalizeUnicode(filename);\n if (Object.hasOwn(result, normalized)) throw new FileNormalizationConflict(filename, result[normalized]!);\n result[normalized] = filename;\n }\n return result;\n}\nexport const encodeFilename = (s: string): string => s.replace(/\\r/g, '%0D').replace(/\\n/g, '%0A');\nexport const decodeFilename = (s: string): string => s.replace(/%0d/gi, '\\r').replace(/%0a/gi, '\\n');\nexport const posixPath = (s: string): string => s.split(sep).join('/');\nexport const isFile = (p: string): boolean => { try { return statSync(p).isFile(); } catch { return false; } };\nexport const isDirectory = (p: string): boolean => { try { return statSync(p).isDirectory(); } catch { return false; } };\n\n/** Match os.walk: sorted files at each level, then sorted directories; do not follow directory symlinks. */\nexport function* walkFiles(root: string, prefix = ''): Generator<string> {\n if (!isDirectory(root)) return;\n const entries = readdirSync(root, { withFileTypes: true }).sort((a, b) => compareNames(a.name, b.name));\n for (const e of entries) {\n const p = join(root, e.name);\n if (e.isFile() || (e.isSymbolicLink() && !isDirectory(p))) yield prefix + e.name;\n }\n for (const e of entries) if (e.isDirectory()) yield* walkFiles(join(root, e.name), `${prefix}${e.name}/`);\n}\nexport function compareNames(a: string, b: string): number {\n // Python sorts Unicode code points, whereas JavaScript's default sort uses UTF-16 code units.\n const ac = Array.from(a, c => c.codePointAt(0)!);\n const bc = Array.from(b, c => c.codePointAt(0)!);\n for (let i = 0; i < Math.min(ac.length, bc.length); i++) if (ac[i] !== bc[i]) return ac[i]! - bc[i]!;\n return ac.length - bc.length;\n}\nfunction canonicalMissingPath(path: string): string {\n if (existsSync(path)) return realpathSync(path);\n const parent = dirname(path);\n if (parent === path) return path;\n // realpath still detects symlinks in the existing part of an absent fetch target.\n return join(canonicalMissingPath(parent), relative(parent, path));\n}\nexport function pathIsDangerous(root: string, filename: string): boolean {\n if (!filename || filename.includes('\\0') || isAbsolute(filename) || win32.isAbsolute(filename) || filename.startsWith('~')) return true;\n const actual = canonicalMissingPath(resolve(root, filename));\n const rel = relative(realpathSync(root), actual);\n return rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel);\n}\nexport function assertSafePath(root: string, filename: string, context = 'manifest'): void {\n if (pathIsDangerous(root, filename)) throw new BagError(`Path \"${filename}\" in ${context} is unsafe`);\n}\nexport function decodeText(bytes: Uint8Array, encoding = 'utf-8'): string {\n let label = encodingLabel(encoding);\n if (label === 'utf-16') {\n if (bytes[0] === 0xfe && bytes[1] === 0xff) label = 'utf-16be';\n else if (bytes[0] === 0xff && bytes[1] === 0xfe) label = 'utf-16le';\n else if (bytes.length) throw new BagValidationError('UTF-16 tag file must begin with a byte-order mark');\n }\n if (label === 'utf-8-sig') return new TextDecoder('utf-8', { fatal: true }).decode(bytes);\n if (label === 'ascii' || label === 'us-ascii') {\n if (bytes.some(b => b > 127)) throw new BagValidationError('Non-ASCII byte in ASCII tag file');\n return Buffer.from(bytes).toString('ascii');\n }\n // TextDecoder maps ISO-8859-1 to Windows-1252; Python uses the actual ISO mapping.\n if (['latin-1', 'latin1', 'iso-8859-1'].includes(label)) return Buffer.from(bytes).toString('latin1');\n try { return new TextDecoder(label, { fatal: true }).decode(bytes); }\n catch (e) { throw new BagValidationError(`Cannot decode tag file as ${encoding}`, [], { cause: e }); }\n}\nexport function checkEncoding(encoding: string): void {\n const label = encodingLabel(encoding);\n if (['utf-8-sig', 'latin-1'].includes(label)) return;\n try { new TextDecoder(label); }\n catch { throw new BagValidationError(`Unsupported encoding: ${encoding}`); }\n}\nexport function encodeText(text: string, encoding = 'utf-8'): Buffer {\n const label = encodingLabel(encoding);\n if (['utf-8', 'utf8', 'utf-8-sig'].includes(label)) {\n const bytes = Buffer.from(text, 'utf8');\n return label === 'utf-8-sig' ? Buffer.concat([Buffer.from([0xef, 0xbb, 0xbf]), bytes]) : bytes;\n }\n if (['utf-16', 'utf-16le', 'utf-16-le', 'utf16le'].includes(label)) {\n const bytes = Buffer.from(text, 'utf16le');\n return label === 'utf-16' ? Buffer.concat([Buffer.from([0xff, 0xfe]), bytes]) : bytes;\n }\n if (['utf-16be', 'utf-16-be'].includes(label)) return Buffer.from(text, 'utf16le').swap16();\n const table = new Map<string, number>();\n for (let b = 0; b < 256; b++) {\n try { const c = decodeText(Uint8Array.of(b), encoding); if (c.length === 1 && !table.has(c)) table.set(c, b); } catch { /* invalid single byte */ }\n }\n const bytes: number[] = [];\n for (const c of text) {\n const b = table.get(c);\n if (b === undefined) throw new BagError(`Cannot encode character ${JSON.stringify(c)} as ${encoding}`);\n bytes.push(b);\n }\n return Buffer.from(bytes);\n}\nfunction encodingLabel(encoding: string): string {\n const label = encoding.toLowerCase().replace(/_/g, '-');\n return ({ utf8: 'utf-8', utf16: 'utf-16', utf16le: 'utf-16le', utf16be: 'utf-16be', 'utf-16-le': 'utf-16le', 'utf-16-be': 'utf-16be' } as Record<string, string>)[label] ?? label;\n}\nexport function parseTagFile(text: string, filename = 'tag file'): BagInfo {\n const result: BagInfo = Object.create(null);\n let key: string | undefined;\n let value = '';\n const emit = (): void => {\n if (!key) return;\n const v = value.trim();\n const prev = result[key];\n result[key] = prev === undefined ? v : Array.isArray(prev) ? [...prev, v] : [prev, v];\n };\n for (const line of text.replace(/\\r\\n?/g, '\\n').match(/[^\\n]*\\n|[^\\n]+$/g) ?? []) {\n if (!line.trim()) continue;\n if (/^\\s/.test(line) && key !== undefined) value += line;\n else {\n emit();\n const colon = line.indexOf(':');\n if (colon < 0) throw new BagValidationError(`${filename} contains invalid tag: ${line.trim()}`);\n key = line.slice(0, colon).trim();\n value = line.slice(colon + 1);\n }\n }\n emit();\n return result;\n}\nexport function serializeTagFile(info: BagInfoInput): string {\n let result = '';\n for (const key of Object.keys(info).sort(compareNames)) {\n if (!key || /[\\r\\n:]/.test(key)) throw new BagError(`Invalid metadata field name: ${key}`);\n const values = Array.isArray(info[key]) ? info[key] : [info[key]];\n for (const value of values!) result += `${key}: ${String(value).replace(/[\\r\\n]/g, '')}\\n`;\n }\n return result;\n}\nexport function makeBagInfo(info: BagInfoInput | undefined, bytes: bigint, files: number): BagInfo {\n const date = new Date();\n const today = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;\n return parseTagFile(serializeTagFile({\n 'Bagging-Date': today,\n 'Bag-Software-Agent': `bagit-node v${VERSION}`,\n ...info,\n 'Payload-Oxum': `${bytes}.${files}`,\n }));\n}\nexport async function loadTagFile(path: string, encoding = 'utf-8'): Promise<BagInfo> {\n return parseTagFile(decodeText(await readFile(path), encoding), path);\n}\nexport function checkPermissions(root: string, saving = false): void {\n try { accessSync(root, constants.R_OK | constants.W_OK | constants.X_OK); }\n catch {\n throw new BagError(saving ? `Cannot save bag to non-existent or inaccessible directory ${root}` : 'Missing permissions to move all files and directories');\n }\n const dirs = [root];\n const files: string[] = [];\n // Finish the write check before reporting unreadable descendants, matching Python.\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i]!;\n try { accessSync(dir, constants.W_OK); }\n catch { throw new BagError('Missing permissions to move all files and directories'); }\n let entries;\n try { entries = readdirSync(dir, { withFileTypes: true }); }\n catch { throw new BagError('Read permissions are required to calculate file fixities'); }\n for (const e of entries) {\n if (e.isDirectory()) dirs.push(join(dir, e.name));\n else files.push(join(dir, e.name));\n }\n }\n for (const p of [...dirs, ...files]) {\n try { accessSync(p, constants.R_OK); }\n catch { throw new BagError('Read permissions are required to calculate file fixities'); }\n }\n}\nexport function checkConcurrency(concurrency = 1): number {\n if (!Number.isSafeInteger(concurrency) || concurrency < 1) throw new RangeError('concurrency must be a positive integer');\n return concurrency;\n}\nexport async function mapConcurrent<T, R>(items: readonly T[], concurrency: number, fn: (value: T) => Promise<R>): Promise<R[]> {\n const result: R[] = new Array(items.length);\n let next = 0;\n let failure: unknown;\n let failed = false;\n await Promise.all(Array.from({ length: Math.min(checkConcurrency(concurrency), items.length) }, async () => {\n while (!failed) {\n const i = next++;\n if (i >= items.length) return;\n try { result[i] = await fn(items[i]!); }\n catch (error) { failed = true; failure = error; }\n }\n }));\n if (failed) throw failure;\n return result;\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Readable, type Writable } from 'node:stream';
|
|
2
|
+
import type { BagInfo, BagInfoInput, Checksums } from './types.js';
|
|
3
|
+
export interface BagZipOptions {
|
|
4
|
+
bagInfo?: BagInfoInput;
|
|
5
|
+
checksums?: readonly string[];
|
|
6
|
+
/** An optional directory containing the entire bag inside the archive. Default: archive root. */
|
|
7
|
+
bagName?: string;
|
|
8
|
+
/** Deflate level 0–9; default 6. */
|
|
9
|
+
compressionLevel?: number;
|
|
10
|
+
/** Temporary directory for manifests; payloads are never staged. */
|
|
11
|
+
tempDirectory?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
/** Fixed ZIP modification time for reproducible archives. */
|
|
14
|
+
mtime?: Date;
|
|
15
|
+
/** Called after a payload file has been completely read into the ZIP compressor. */
|
|
16
|
+
onProgress?: (progress: BagZipProgress) => void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface BagZipProgress {
|
|
19
|
+
path: string;
|
|
20
|
+
bytes: bigint;
|
|
21
|
+
hashes: Checksums;
|
|
22
|
+
totalBytes: bigint;
|
|
23
|
+
totalFiles: number;
|
|
24
|
+
}
|
|
25
|
+
export interface BagZipResult {
|
|
26
|
+
bytesWritten: bigint;
|
|
27
|
+
payloadBytes: bigint;
|
|
28
|
+
payloadFiles: number;
|
|
29
|
+
bagInfo: BagInfo;
|
|
30
|
+
}
|
|
31
|
+
/** Sources are opened lazily, one at a time. Paths are relative to the payload, without a data/ prefix. */
|
|
32
|
+
export interface BagZipEntry {
|
|
33
|
+
path: string;
|
|
34
|
+
/** Preserve an empty directory. Its open() function is ignored. */
|
|
35
|
+
directory?: boolean;
|
|
36
|
+
open: () => Readable | AsyncIterable<Uint8Array> | Iterable<Uint8Array> | Promise<Readable | AsyncIterable<Uint8Array> | Iterable<Uint8Array>>;
|
|
37
|
+
mtime?: Date;
|
|
38
|
+
mode?: number;
|
|
39
|
+
}
|
|
40
|
+
/** Pipe directly into an S3/Ceph multipart upload Body. Errors are emitted on the stream. */
|
|
41
|
+
export declare function createBagZipStream(directory: string, options?: BagZipOptions): Readable;
|
|
42
|
+
/** Stream a bag from lazy application-provided sources, without first creating a payload directory. */
|
|
43
|
+
export declare function createBagZipStreamFromEntries(entries: AsyncIterable<BagZipEntry> | Iterable<BagZipEntry>, options?: BagZipOptions): Readable;
|
|
44
|
+
/** Write an archive to a Writable, or atomically replace a path after successful completion. Ends the destination. */
|
|
45
|
+
export declare function folderToBagZip(directory: string, destination: string | Writable, options?: BagZipOptions): Promise<BagZipResult>;
|
|
46
|
+
export declare const folderToBagitZip: typeof folderToBagZip;
|
|
47
|
+
//# sourceMappingURL=zip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../../src/zip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQt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