bagit-node 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/NOTICE +6 -0
- package/README.md +246 -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 +49 -0
- package/dist/cjs/zip.d.ts.map +1 -0
- package/dist/cjs/zip.js +371 -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 +49 -0
- package/dist/esm/zip.d.ts.map +1 -0
- package/dist/esm/zip.js +365 -0
- package/dist/esm/zip.js.map +1 -0
- package/package.json +47 -4
package/dist/esm/bag.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { chmod, mkdtemp, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { BagError, BagValidationError, ChecksumMismatch, FileMissing, UnexpectedFile } from './errors.js';
|
|
5
|
+
import { algorithmsFor, assertSafePath, BAG_DECLARATION, buildUnicodeNormalizedLookupDict, checkConcurrency, checkEncoding, checkPermissions, CHECKSUM_ALGOS, decodeFilename, decodeText, DEFAULT_CHECKSUMS, encodeFilename, encodeText, hashFile, isDirectory, isFile, makeBagInfo, mapConcurrent, normalizeUnicode, parseTagFile, serializeTagFile, walkFiles, } from './util.js';
|
|
6
|
+
export class Bag {
|
|
7
|
+
path;
|
|
8
|
+
tags = Object.create(null);
|
|
9
|
+
info = Object.create(null);
|
|
10
|
+
entries = Object.create(null);
|
|
11
|
+
algorithms = [];
|
|
12
|
+
versionInfo;
|
|
13
|
+
version;
|
|
14
|
+
encoding;
|
|
15
|
+
tagFileName;
|
|
16
|
+
normalizedFilesystemNames = Object.create(null);
|
|
17
|
+
normalizedManifestNames = Object.create(null);
|
|
18
|
+
/** Reads declaration, metadata and manifests synchronously; file hashing is asynchronous. */
|
|
19
|
+
constructor(path) {
|
|
20
|
+
this.path = resolve(path);
|
|
21
|
+
const declaration = join(this.path, 'bagit.txt');
|
|
22
|
+
if (!isFile(declaration))
|
|
23
|
+
throw new BagError(`Expected bagit.txt does not exist: ${declaration}`);
|
|
24
|
+
this.tags = parseTagFile(decodeText(readFileSync(declaration)), 'bagit.txt');
|
|
25
|
+
const missing = ['BagIt-Version', 'Tag-File-Character-Encoding'].filter(k => !(k in this.tags));
|
|
26
|
+
if (missing.length)
|
|
27
|
+
throw new BagError(`Missing required tag in bagit.txt: ${missing.join(', ')}`);
|
|
28
|
+
const version = this.tags['BagIt-Version'];
|
|
29
|
+
if (typeof version !== 'string' || !/^\d+\.\d+$/.test(version)) {
|
|
30
|
+
throw new BagError(`Bag version numbers must be MAJOR.MINOR numbers, not ${String(version)}`);
|
|
31
|
+
}
|
|
32
|
+
this.version = version;
|
|
33
|
+
const [major, minor] = version.split('.').map(Number);
|
|
34
|
+
this.versionInfo = [major, minor];
|
|
35
|
+
if (major === 0 && minor >= 93 && minor <= 95)
|
|
36
|
+
this.tagFileName = 'package-info.txt';
|
|
37
|
+
else if ((major === 0 && minor >= 96) || major === 1)
|
|
38
|
+
this.tagFileName = 'bag-info.txt';
|
|
39
|
+
else
|
|
40
|
+
throw new BagError(`Unsupported bag version: ${version}`);
|
|
41
|
+
const encoding = this.tags['Tag-File-Character-Encoding'];
|
|
42
|
+
if (typeof encoding !== 'string')
|
|
43
|
+
throw new BagValidationError('Tag-File-Character-Encoding must occur once');
|
|
44
|
+
this.encoding = encoding;
|
|
45
|
+
checkEncoding(encoding);
|
|
46
|
+
const infoPath = join(this.path, this.tagFileName);
|
|
47
|
+
if (isFile(infoPath))
|
|
48
|
+
this.info = parseTagFile(decodeText(readFileSync(infoPath), encoding), this.tagFileName);
|
|
49
|
+
this.loadManifests();
|
|
50
|
+
}
|
|
51
|
+
toString() { return this.path; }
|
|
52
|
+
get algs() { return this.algorithms; }
|
|
53
|
+
get version_info() { return this.versionInfo; }
|
|
54
|
+
get tag_file_name() { return this.tagFileName; }
|
|
55
|
+
get verifiesTagFiles() { return this.versionInfo[0] >= 1 || this.versionInfo[1] >= 97; }
|
|
56
|
+
*manifestFiles() {
|
|
57
|
+
for (const a of CHECKSUM_ALGOS)
|
|
58
|
+
if (isFile(join(this.path, `manifest-${a}.txt`)))
|
|
59
|
+
yield join(this.path, `manifest-${a}.txt`);
|
|
60
|
+
}
|
|
61
|
+
*tagmanifestFiles() {
|
|
62
|
+
for (const a of CHECKSUM_ALGOS)
|
|
63
|
+
if (isFile(join(this.path, `tagmanifest-${a}.txt`)))
|
|
64
|
+
yield join(this.path, `tagmanifest-${a}.txt`);
|
|
65
|
+
}
|
|
66
|
+
loadManifests() {
|
|
67
|
+
this.entries = Object.create(null);
|
|
68
|
+
this.algorithms = [];
|
|
69
|
+
const manifests = [...this.manifestFiles(), ...(this.verifiesTagFiles ? this.tagmanifestFiles() : [])];
|
|
70
|
+
for (const manifest of manifests) {
|
|
71
|
+
const algorithm = basename(manifest).replace(/^(?:tag)?manifest-/, '').replace(/\.txt$/, '');
|
|
72
|
+
if (!this.algorithms.includes(algorithm))
|
|
73
|
+
this.algorithms.push(algorithm);
|
|
74
|
+
const text = decodeText(readFileSync(manifest), this.encoding);
|
|
75
|
+
for (const raw of text.split(/\r\n|\n|\r/)) {
|
|
76
|
+
const line = raw.trim();
|
|
77
|
+
if (!line || line.startsWith('#'))
|
|
78
|
+
continue;
|
|
79
|
+
const entry = /^(\S+)\s+(.+)$/.exec(line);
|
|
80
|
+
if (!entry)
|
|
81
|
+
continue; // Python logs and skips malformed lines.
|
|
82
|
+
const digest = entry[1];
|
|
83
|
+
const filename = decodeFilename(posix.normalize(entry[2].replace(/^\*+/, '')));
|
|
84
|
+
assertSafePath(this.path, filename, `manifest "${manifest}"`);
|
|
85
|
+
const hashes = this.entries[filename] ??= Object.create(null);
|
|
86
|
+
if (Object.hasOwn(hashes, algorithm)) {
|
|
87
|
+
const same = hashes[algorithm] === digest;
|
|
88
|
+
if (!same || this.versionInfo[0] >= 1) {
|
|
89
|
+
throw new BagError(`${this.path}: ${algorithm} manifest lists ${filename} multiple times with ${same ? 'the same value' : 'conflicting values'}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
hashes[algorithm] = digest;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this.normalizedManifestNames = buildUnicodeNormalizedLookupDict(Object.keys(this.entries));
|
|
96
|
+
}
|
|
97
|
+
*payloadFiles() {
|
|
98
|
+
this.normalizedFilesystemNames = Object.create(null);
|
|
99
|
+
for (const filename of walkFiles(join(this.path, 'data'), 'data/')) {
|
|
100
|
+
this.normalizedFilesystemNames[normalizeUnicode(filename)] = filename;
|
|
101
|
+
yield filename;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
payloadEntries() { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => p.startsWith('data/'))); }
|
|
105
|
+
tagfileEntries() { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => !p.startsWith('data/'))); }
|
|
106
|
+
*missingOptionalTagfiles() {
|
|
107
|
+
for (const filename of Object.keys(this.tagfileEntries()))
|
|
108
|
+
if (!isFile(join(this.path, filename)))
|
|
109
|
+
yield filename;
|
|
110
|
+
}
|
|
111
|
+
compareManifestsWithFs() {
|
|
112
|
+
const files = [...this.payloadFiles()];
|
|
113
|
+
this.normalizedFilesystemNames = buildUnicodeNormalizedLookupDict(files);
|
|
114
|
+
const onFs = new Set(files.map(normalizeUnicode));
|
|
115
|
+
const inManifest = new Set(Object.keys(this.payloadEntries()).map(normalizeUnicode));
|
|
116
|
+
if (this.verifiesTagFiles)
|
|
117
|
+
for (const f of this.missingOptionalTagfiles())
|
|
118
|
+
inManifest.add(normalizeUnicode(f));
|
|
119
|
+
return [
|
|
120
|
+
[...inManifest].filter(p => !onFs.has(p)).map(p => this.normalizedManifestNames[p]),
|
|
121
|
+
[...onFs].filter(p => !inManifest.has(p)).map(p => this.normalizedFilesystemNames[p]),
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
*fetchEntries() {
|
|
125
|
+
const path = join(this.path, 'fetch.txt');
|
|
126
|
+
if (!isFile(path))
|
|
127
|
+
return;
|
|
128
|
+
for (const line of decodeText(readFileSync(path), this.encoding).split(/\r\n|\n|\r/)) {
|
|
129
|
+
if (!line.trim())
|
|
130
|
+
continue;
|
|
131
|
+
const parts = /^(\S+)\s+(\S+)\s+(.+)$/.exec(line.trim());
|
|
132
|
+
if (!parts)
|
|
133
|
+
throw new BagError(`Malformed entry in fetch.txt: ${line}`);
|
|
134
|
+
const filename = parts[3];
|
|
135
|
+
assertSafePath(this.path, filename, `"${path}"`);
|
|
136
|
+
yield [parts[1], parts[2], filename];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
*filesToBeFetched() { for (const [, , filename] of this.fetchEntries())
|
|
140
|
+
yield filename; }
|
|
141
|
+
compareFetchWithFs() {
|
|
142
|
+
const files = new Set(this.payloadFiles());
|
|
143
|
+
return [...new Set(this.filesToBeFetched())].filter(f => !files.has(f));
|
|
144
|
+
}
|
|
145
|
+
validateFetch() {
|
|
146
|
+
for (const [url] of this.fetchEntries()) {
|
|
147
|
+
// Like urllib.urlparse: permit any scheme with an authority, or file: URLs.
|
|
148
|
+
if (!/^file:/i.test(url) && !/^[a-z][a-z\d+.-]*:\/\/[^/\s?#]+/i.test(url))
|
|
149
|
+
throw new BagError(`Malformed URL in fetch.txt: ${url}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
hasOxum() { return Object.hasOwn(this.info, 'Payload-Oxum'); }
|
|
153
|
+
async validate(options = {}) {
|
|
154
|
+
const concurrency = checkConcurrency(options.concurrency);
|
|
155
|
+
options.signal?.throwIfAborted();
|
|
156
|
+
if (!isDirectory(join(this.path, 'data')))
|
|
157
|
+
throw new BagValidationError(`Expected data directory ${join(this.path, 'data')} does not exist`);
|
|
158
|
+
if (![...this.manifestFiles()].length)
|
|
159
|
+
throw new BagValidationError('No manifest files found');
|
|
160
|
+
const declaration = join(this.path, 'bagit.txt');
|
|
161
|
+
if (!isFile(declaration))
|
|
162
|
+
throw new BagValidationError(`Expected ${this.path} to contain "bagit.txt"`);
|
|
163
|
+
if (readFileSync(declaration).subarray(0, 3).equals(Buffer.from([0xef, 0xbb, 0xbf])))
|
|
164
|
+
throw new BagValidationError('bagit.txt must not contain a byte-order mark');
|
|
165
|
+
this.validateFetch();
|
|
166
|
+
if (options.fast && !this.hasOxum())
|
|
167
|
+
throw new BagValidationError('Fast validation requires bag-info.txt to include Payload-Oxum');
|
|
168
|
+
this.validateOxum();
|
|
169
|
+
if (options.fast)
|
|
170
|
+
return true;
|
|
171
|
+
const [missing, unexpected] = this.compareManifestsWithFs();
|
|
172
|
+
const errors = [...missing.map(p => new FileMissing(p)), ...unexpected.map(p => new UnexpectedFile(p))];
|
|
173
|
+
if (errors.length)
|
|
174
|
+
throw new BagValidationError('Bag is incomplete', errors);
|
|
175
|
+
if (options.completenessOnly || options.completeness_only)
|
|
176
|
+
return true;
|
|
177
|
+
const results = await mapConcurrent(Object.entries(this.entries), concurrency, async ([filename, expected]) => {
|
|
178
|
+
options.signal?.throwIfAborted();
|
|
179
|
+
const actualName = this.normalizedFilesystemNames[normalizeUnicode(filename)] ?? filename;
|
|
180
|
+
assertSafePath(this.path, actualName);
|
|
181
|
+
let hashes;
|
|
182
|
+
try {
|
|
183
|
+
({ hashes } = await hashFile(join(this.path, actualName), Object.keys(expected), options.signal));
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (!(error instanceof BagValidationError))
|
|
187
|
+
throw error;
|
|
188
|
+
hashes = Object.fromEntries(Object.keys(expected).map(a => [a, error.message]));
|
|
189
|
+
}
|
|
190
|
+
return Object.entries(expected).filter(([a, h]) => h.toLowerCase() !== hashes[a]).map(([a, h]) => new ChecksumMismatch(filename, a, h.toLowerCase(), hashes[a]));
|
|
191
|
+
});
|
|
192
|
+
errors.push(...results.flat());
|
|
193
|
+
if (errors.length)
|
|
194
|
+
throw new BagValidationError('Bag validation failed', errors);
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
validateOxum() {
|
|
198
|
+
let oxum = this.info['Payload-Oxum'];
|
|
199
|
+
if (oxum === undefined)
|
|
200
|
+
return;
|
|
201
|
+
if (Array.isArray(oxum))
|
|
202
|
+
oxum = oxum[0];
|
|
203
|
+
if (!/^\d+\.\d+$/.test(oxum))
|
|
204
|
+
throw new BagError(`Malformed Payload-Oxum value: ${oxum}`);
|
|
205
|
+
const [expectedBytes, expectedFiles] = oxum.split('.').map(BigInt);
|
|
206
|
+
const files = [...this.payloadFiles()];
|
|
207
|
+
let bytes = 0n;
|
|
208
|
+
for (const f of files) {
|
|
209
|
+
assertSafePath(this.path, f);
|
|
210
|
+
bytes += statSync(join(this.path, f), { bigint: true }).size;
|
|
211
|
+
}
|
|
212
|
+
if (bytes !== expectedBytes || BigInt(files.length) !== expectedFiles) {
|
|
213
|
+
throw new BagValidationError(`Payload-Oxum validation failed. Expected ${expectedFiles} files and ${expectedBytes} bytes but found ${files.length} files and ${bytes} bytes`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async isValid(options = {}) {
|
|
217
|
+
try {
|
|
218
|
+
await this.validate(options);
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
if (error instanceof BagError)
|
|
223
|
+
return false;
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async save(options = {}) {
|
|
228
|
+
checkConcurrency(options.concurrency);
|
|
229
|
+
options.signal?.throwIfAborted();
|
|
230
|
+
checkPermissions(this.path, true);
|
|
231
|
+
if (options.manifests) {
|
|
232
|
+
const { bytes, files } = await makeManifests(this.path, { checksums: this.algorithms, concurrency: options.concurrency, signal: options.signal }, this.encoding);
|
|
233
|
+
this.info['Payload-Oxum'] = `${bytes}.${files}`;
|
|
234
|
+
}
|
|
235
|
+
await writeFile(join(this.path, this.tagFileName), encodeText(serializeTagFile(this.info), this.encoding));
|
|
236
|
+
await makeTagManifests(this.path, this.algorithms, this.encoding, options.signal);
|
|
237
|
+
this.loadManifests();
|
|
238
|
+
}
|
|
239
|
+
// Python-style method aliases ease migration while the primary API uses Node naming conventions.
|
|
240
|
+
manifest_files = this.manifestFiles;
|
|
241
|
+
tagmanifest_files = this.tagmanifestFiles;
|
|
242
|
+
payload_files = this.payloadFiles;
|
|
243
|
+
payload_entries = this.payloadEntries;
|
|
244
|
+
tagfile_entries = this.tagfileEntries;
|
|
245
|
+
missing_optional_tagfiles = this.missingOptionalTagfiles;
|
|
246
|
+
compare_manifests_with_fs = this.compareManifestsWithFs;
|
|
247
|
+
compare_fetch_with_fs = this.compareFetchWithFs;
|
|
248
|
+
fetch_entries = this.fetchEntries;
|
|
249
|
+
files_to_be_fetched = this.filesToBeFetched;
|
|
250
|
+
validate_fetch = this.validateFetch;
|
|
251
|
+
has_oxum = this.hasOxum;
|
|
252
|
+
is_valid = this.isValid;
|
|
253
|
+
}
|
|
254
|
+
/** Convert a directory in place. Existing contents, including an existing data/, become payload. */
|
|
255
|
+
export async function makeBag(directory, options = {}) {
|
|
256
|
+
const root = resolve(directory);
|
|
257
|
+
const algorithms = algorithmsFor(options.checksums);
|
|
258
|
+
checkConcurrency(options.concurrency);
|
|
259
|
+
if (options.encoding && options.encoding.toLowerCase() !== 'utf-8')
|
|
260
|
+
throw new BagError('New bags must use UTF-8');
|
|
261
|
+
options.signal?.throwIfAborted();
|
|
262
|
+
if (!isDirectory(root))
|
|
263
|
+
throw new BagError(`Bag directory ${root} does not exist`);
|
|
264
|
+
const cwdRelative = relative(root, process.cwd());
|
|
265
|
+
if (cwdRelative && !cwdRelative.startsWith(`..${sep}`) && cwdRelative !== '..' && !isAbsolute(cwdRelative)) {
|
|
266
|
+
throw new BagError('Bagging a parent of the current directory is not supported');
|
|
267
|
+
}
|
|
268
|
+
checkPermissions(root);
|
|
269
|
+
const sourceFiles = [...walkFiles(root)];
|
|
270
|
+
buildUnicodeNormalizedLookupDict(sourceFiles);
|
|
271
|
+
for (const f of sourceFiles)
|
|
272
|
+
assertSafePath(root, f, 'source directory');
|
|
273
|
+
const originalMode = (await stat(root)).mode;
|
|
274
|
+
const children = await readdir(root);
|
|
275
|
+
const staging = await mkdtemp(join(root, '.bagit-'));
|
|
276
|
+
const moved = [];
|
|
277
|
+
try {
|
|
278
|
+
for (const name of children) {
|
|
279
|
+
await rename(join(root, name), join(staging, name));
|
|
280
|
+
moved.push(name);
|
|
281
|
+
}
|
|
282
|
+
await rename(staging, join(root, 'data'));
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
for (const name of moved.reverse())
|
|
286
|
+
await rename(join(staging, name), join(root, name));
|
|
287
|
+
await rm(staging, { recursive: true, force: true });
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
await chmod(join(root, 'data'), originalMode);
|
|
291
|
+
const { bytes, files } = await makeManifests(root, { ...options, checksums: algorithms });
|
|
292
|
+
await writeFile(join(root, 'bagit.txt'), BAG_DECLARATION);
|
|
293
|
+
await writeFile(join(root, 'bag-info.txt'), serializeTagFile(makeBagInfo(options.bagInfo, bytes, files)));
|
|
294
|
+
await makeTagManifests(root, algorithms, 'utf-8', options.signal);
|
|
295
|
+
return new Bag(root);
|
|
296
|
+
}
|
|
297
|
+
export async function makeManifests(root, options = {}, encoding = 'utf-8') {
|
|
298
|
+
const algorithms = algorithmsFor(options.checksums);
|
|
299
|
+
const filenames = [...walkFiles(join(root, 'data'), 'data/')];
|
|
300
|
+
buildUnicodeNormalizedLookupDict(filenames);
|
|
301
|
+
const records = await mapConcurrent(filenames, options.concurrency ?? 1, async (filename) => {
|
|
302
|
+
assertSafePath(root, filename);
|
|
303
|
+
return { filename, ...await hashFile(join(root, filename), algorithms, options.signal) };
|
|
304
|
+
});
|
|
305
|
+
for (const a of algorithms) {
|
|
306
|
+
const text = records.map(r => `${r.hashes[a]} ${encodeFilename(r.filename)}\n`).join('');
|
|
307
|
+
await writeFile(join(root, `manifest-${a}.txt`), encodeText(text, encoding));
|
|
308
|
+
}
|
|
309
|
+
return { bytes: records.reduce((sum, r) => sum + r.bytes, 0n), files: records.length };
|
|
310
|
+
}
|
|
311
|
+
export async function makeTagManifests(root, algorithms = DEFAULT_CHECKSUMS, encoding = 'utf-8', signal) {
|
|
312
|
+
const tagFiles = [...walkFiles(root)].filter(f => !f.startsWith('data/') && !basename(f).startsWith('tagmanifest-'));
|
|
313
|
+
const records = [];
|
|
314
|
+
for (const filename of tagFiles) {
|
|
315
|
+
assertSafePath(root, filename);
|
|
316
|
+
records.push({ filename, ...await hashFile(join(root, filename), algorithms, signal) });
|
|
317
|
+
}
|
|
318
|
+
for (const a of algorithmsFor(algorithms)) {
|
|
319
|
+
await writeFile(join(root, `tagmanifest-${a}.txt`), encodeText(records.map(r => `${r.hashes[a]} ${encodeFilename(r.filename)}\n`).join(''), encoding));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=bag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bag.js","sourceRoot":"","sources":["../../src/bag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAA4B,MAAM,aAAa,CAAC;AAEpI,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,gCAAgC,EAAE,gBAAgB,EAClG,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAC9F,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,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AE,QAAQ,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;IACzJ,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync, statSync } from 'node:fs';\nimport { chmod, mkdtemp, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';\nimport { basename, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';\nimport { BagError, BagValidationError, ChecksumMismatch, FileMissing, UnexpectedFile, type ManifestErrorDetail } from './errors.js';\nimport type { BagInfo, Checksums, Entries, FetchEntry, MakeBagOptions, SaveOptions, ValidationOptions } from './types.js';\nimport {\n algorithmsFor, assertSafePath, BAG_DECLARATION, buildUnicodeNormalizedLookupDict, checkConcurrency,\n checkEncoding, checkPermissions, CHECKSUM_ALGOS, decodeFilename, decodeText, DEFAULT_CHECKSUMS,\n encodeFilename, encodeText, hashFile, isDirectory, isFile, makeBagInfo, mapConcurrent, normalizeUnicode,\n parseTagFile, serializeTagFile, walkFiles,\n} from './util.js';\n\nexport class Bag {\n readonly path: string;\n tags: BagInfo = Object.create(null);\n info: BagInfo = Object.create(null);\n entries: Entries = Object.create(null);\n algorithms: string[] = [];\n versionInfo!: readonly [number, number];\n version!: string;\n encoding!: string;\n tagFileName!: string;\n normalizedFilesystemNames: Record<string, string> = Object.create(null);\n normalizedManifestNames: Record<string, string> = Object.create(null);\n\n /** Reads declaration, metadata and manifests synchronously; file hashing is asynchronous. */\n constructor(path: string) {\n this.path = resolve(path);\n const declaration = join(this.path, 'bagit.txt');\n if (!isFile(declaration)) throw new BagError(`Expected bagit.txt does not exist: ${declaration}`);\n this.tags = parseTagFile(decodeText(readFileSync(declaration)), 'bagit.txt');\n const missing = ['BagIt-Version', 'Tag-File-Character-Encoding'].filter(k => !(k in this.tags));\n if (missing.length) throw new BagError(`Missing required tag in bagit.txt: ${missing.join(', ')}`);\n const version = this.tags['BagIt-Version'];\n if (typeof version !== 'string' || !/^\\d+\\.\\d+$/.test(version)) {\n throw new BagError(`Bag version numbers must be MAJOR.MINOR numbers, not ${String(version)}`);\n }\n this.version = version;\n const [major, minor] = version.split('.').map(Number) as [number, number];\n this.versionInfo = [major, minor];\n if (major === 0 && minor >= 93 && minor <= 95) this.tagFileName = 'package-info.txt';\n else if ((major === 0 && minor >= 96) || major === 1) this.tagFileName = 'bag-info.txt';\n else throw new BagError(`Unsupported bag version: ${version}`);\n const encoding = this.tags['Tag-File-Character-Encoding'];\n if (typeof encoding !== 'string') throw new BagValidationError('Tag-File-Character-Encoding must occur once');\n this.encoding = encoding;\n checkEncoding(encoding);\n const infoPath = join(this.path, this.tagFileName);\n if (isFile(infoPath)) this.info = parseTagFile(decodeText(readFileSync(infoPath), encoding), this.tagFileName);\n this.loadManifests();\n }\n\n toString(): string { return this.path; }\n get algs(): string[] { return this.algorithms; }\n get version_info(): readonly [number, number] { return this.versionInfo; }\n get tag_file_name(): string { return this.tagFileName; }\n private get verifiesTagFiles(): boolean { return this.versionInfo[0] >= 1 || this.versionInfo[1] >= 97; }\n\n *manifestFiles(): Generator<string> {\n for (const a of CHECKSUM_ALGOS) if (isFile(join(this.path, `manifest-${a}.txt`))) yield join(this.path, `manifest-${a}.txt`);\n }\n *tagmanifestFiles(): Generator<string> {\n for (const a of CHECKSUM_ALGOS) if (isFile(join(this.path, `tagmanifest-${a}.txt`))) yield join(this.path, `tagmanifest-${a}.txt`);\n }\n private loadManifests(): void {\n this.entries = Object.create(null);\n this.algorithms = [];\n const manifests = [...this.manifestFiles(), ...(this.verifiesTagFiles ? this.tagmanifestFiles() : [])];\n for (const manifest of manifests) {\n const algorithm = basename(manifest).replace(/^(?:tag)?manifest-/, '').replace(/\\.txt$/, '');\n if (!this.algorithms.includes(algorithm)) this.algorithms.push(algorithm);\n const text = decodeText(readFileSync(manifest), this.encoding);\n for (const raw of text.split(/\\r\\n|\\n|\\r/)) {\n const line = raw.trim();\n if (!line || line.startsWith('#')) continue;\n const entry = /^(\\S+)\\s+(.+)$/.exec(line);\n if (!entry) continue; // Python logs and skips malformed lines.\n const digest = entry[1]!;\n const filename = decodeFilename(posix.normalize(entry[2]!.replace(/^\\*+/, '')));\n assertSafePath(this.path, filename, `manifest \"${manifest}\"`);\n const hashes = this.entries[filename] ??= Object.create(null) as Checksums;\n if (Object.hasOwn(hashes, algorithm)) {\n const same = hashes[algorithm] === digest;\n if (!same || this.versionInfo[0] >= 1) {\n throw new BagError(`${this.path}: ${algorithm} manifest lists ${filename} multiple times with ${same ? 'the same value' : 'conflicting values'}`);\n }\n }\n hashes[algorithm] = digest;\n }\n }\n this.normalizedManifestNames = buildUnicodeNormalizedLookupDict(Object.keys(this.entries));\n }\n *payloadFiles(): Generator<string> {\n this.normalizedFilesystemNames = Object.create(null);\n for (const filename of walkFiles(join(this.path, 'data'), 'data/')) {\n this.normalizedFilesystemNames[normalizeUnicode(filename)] = filename;\n yield filename;\n }\n }\n payloadEntries(): Entries { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => p.startsWith('data/'))); }\n tagfileEntries(): Entries { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => !p.startsWith('data/'))); }\n *missingOptionalTagfiles(): Generator<string> {\n for (const filename of Object.keys(this.tagfileEntries())) if (!isFile(join(this.path, filename))) yield filename;\n }\n compareManifestsWithFs(): [string[], string[]] {\n const files = [...this.payloadFiles()];\n this.normalizedFilesystemNames = buildUnicodeNormalizedLookupDict(files);\n const onFs = new Set(files.map(normalizeUnicode));\n const inManifest = new Set(Object.keys(this.payloadEntries()).map(normalizeUnicode));\n if (this.verifiesTagFiles) for (const f of this.missingOptionalTagfiles()) inManifest.add(normalizeUnicode(f));\n return [\n [...inManifest].filter(p => !onFs.has(p)).map(p => this.normalizedManifestNames[p]!),\n [...onFs].filter(p => !inManifest.has(p)).map(p => this.normalizedFilesystemNames[p]!),\n ];\n }\n *fetchEntries(): Generator<FetchEntry> {\n const path = join(this.path, 'fetch.txt');\n if (!isFile(path)) return;\n for (const line of decodeText(readFileSync(path), this.encoding).split(/\\r\\n|\\n|\\r/)) {\n if (!line.trim()) continue;\n const parts = /^(\\S+)\\s+(\\S+)\\s+(.+)$/.exec(line.trim());\n if (!parts) throw new BagError(`Malformed entry in fetch.txt: ${line}`);\n const filename = parts[3]!;\n assertSafePath(this.path, filename, `\"${path}\"`);\n yield [parts[1]!, parts[2]!, filename];\n }\n }\n *filesToBeFetched(): Generator<string> { for (const [, , filename] of this.fetchEntries()) yield filename; }\n compareFetchWithFs(): string[] {\n const files = new Set(this.payloadFiles());\n return [...new Set(this.filesToBeFetched())].filter(f => !files.has(f));\n }\n validateFetch(): void {\n for (const [url] of this.fetchEntries()) {\n // Like urllib.urlparse: permit any scheme with an authority, or file: URLs.\n if (!/^file:/i.test(url) && !/^[a-z][a-z\\d+.-]*:\\/\\/[^/\\s?#]+/i.test(url)) throw new BagError(`Malformed URL in fetch.txt: ${url}`);\n }\n }\n hasOxum(): boolean { return Object.hasOwn(this.info, 'Payload-Oxum'); }\n\n async validate(options: ValidationOptions = {}): Promise<true> {\n const concurrency = checkConcurrency(options.concurrency);\n options.signal?.throwIfAborted();\n if (!isDirectory(join(this.path, 'data'))) throw new BagValidationError(`Expected data directory ${join(this.path, 'data')} does not exist`);\n if (![...this.manifestFiles()].length) throw new BagValidationError('No manifest files found');\n const declaration = join(this.path, 'bagit.txt');\n if (!isFile(declaration)) throw new BagValidationError(`Expected ${this.path} to contain \"bagit.txt\"`);\n if (readFileSync(declaration).subarray(0, 3).equals(Buffer.from([0xef, 0xbb, 0xbf]))) throw new BagValidationError('bagit.txt must not contain a byte-order mark');\n this.validateFetch();\n if (options.fast && !this.hasOxum()) throw new BagValidationError('Fast validation requires bag-info.txt to include Payload-Oxum');\n this.validateOxum();\n if (options.fast) return true;\n const [missing, unexpected] = this.compareManifestsWithFs();\n const errors: ManifestErrorDetail[] = [...missing.map(p => new FileMissing(p)), ...unexpected.map(p => new UnexpectedFile(p))];\n if (errors.length) throw new BagValidationError('Bag is incomplete', errors);\n if (options.completenessOnly || options.completeness_only) return true;\n const results = await mapConcurrent(Object.entries(this.entries), concurrency, async ([filename, expected]) => {\n options.signal?.throwIfAborted();\n const actualName = this.normalizedFilesystemNames[normalizeUnicode(filename)] ?? filename;\n assertSafePath(this.path, actualName);\n let hashes: Checksums;\n try { ({ hashes } = await hashFile(join(this.path, actualName), Object.keys(expected), options.signal)); }\n catch (error) {\n if (!(error instanceof BagValidationError)) throw error;\n hashes = Object.fromEntries(Object.keys(expected).map(a => [a, error.message]));\n }\n return Object.entries(expected).filter(([a, h]) => h.toLowerCase() !== hashes[a]).map(([a, h]) => new ChecksumMismatch(filename, a, h.toLowerCase(), hashes[a]!));\n });\n errors.push(...results.flat());\n if (errors.length) throw new BagValidationError('Bag validation failed', errors);\n return true;\n }\n private validateOxum(): void {\n let oxum = this.info['Payload-Oxum'];\n if (oxum === undefined) return;\n if (Array.isArray(oxum)) oxum = oxum[0]!;\n if (!/^\\d+\\.\\d+$/.test(oxum)) throw new BagError(`Malformed Payload-Oxum value: ${oxum}`);\n const [expectedBytes, expectedFiles] = oxum.split('.').map(BigInt);\n const files = [...this.payloadFiles()];\n let bytes = 0n;\n for (const f of files) {\n assertSafePath(this.path, f);\n bytes += statSync(join(this.path, f), { bigint: true }).size;\n }\n if (bytes !== expectedBytes || BigInt(files.length) !== expectedFiles) {\n throw new BagValidationError(`Payload-Oxum validation failed. Expected ${expectedFiles} files and ${expectedBytes} bytes but found ${files.length} files and ${bytes} bytes`);\n }\n }\n async isValid(options: ValidationOptions = {}): Promise<boolean> {\n try { await this.validate(options); return true; }\n catch (error) { if (error instanceof BagError) return false; throw error; }\n }\n async save(options: SaveOptions = {}): Promise<void> {\n checkConcurrency(options.concurrency);\n options.signal?.throwIfAborted();\n checkPermissions(this.path, true);\n if (options.manifests) {\n const { bytes, files } = await makeManifests(this.path, { checksums: this.algorithms, concurrency: options.concurrency, signal: options.signal }, this.encoding);\n this.info['Payload-Oxum'] = `${bytes}.${files}`;\n }\n await writeFile(join(this.path, this.tagFileName), encodeText(serializeTagFile(this.info), this.encoding));\n await makeTagManifests(this.path, this.algorithms, this.encoding, options.signal);\n this.loadManifests();\n }\n\n // Python-style method aliases ease migration while the primary API uses Node naming conventions.\n manifest_files = this.manifestFiles;\n tagmanifest_files = this.tagmanifestFiles;\n payload_files = this.payloadFiles;\n payload_entries = this.payloadEntries;\n tagfile_entries = this.tagfileEntries;\n missing_optional_tagfiles = this.missingOptionalTagfiles;\n compare_manifests_with_fs = this.compareManifestsWithFs;\n compare_fetch_with_fs = this.compareFetchWithFs;\n fetch_entries = this.fetchEntries;\n files_to_be_fetched = this.filesToBeFetched;\n validate_fetch = this.validateFetch;\n has_oxum = this.hasOxum;\n is_valid = this.isValid;\n}\n\n/** Convert a directory in place. Existing contents, including an existing data/, become payload. */\nexport async function makeBag(directory: string, options: MakeBagOptions = {}): Promise<Bag> {\n const root = resolve(directory);\n const algorithms = algorithmsFor(options.checksums);\n checkConcurrency(options.concurrency);\n if (options.encoding && options.encoding.toLowerCase() !== 'utf-8') throw new BagError('New bags must use UTF-8');\n options.signal?.throwIfAborted();\n if (!isDirectory(root)) throw new BagError(`Bag directory ${root} does not exist`);\n const cwdRelative = relative(root, process.cwd());\n if (cwdRelative && !cwdRelative.startsWith(`..${sep}`) && cwdRelative !== '..' && !isAbsolute(cwdRelative)) {\n throw new BagError('Bagging a parent of the current directory is not supported');\n }\n checkPermissions(root);\n const sourceFiles = [...walkFiles(root)];\n buildUnicodeNormalizedLookupDict(sourceFiles);\n for (const f of sourceFiles) assertSafePath(root, f, 'source directory');\n const originalMode = (await stat(root)).mode;\n const children = await readdir(root);\n const staging = await mkdtemp(join(root, '.bagit-'));\n const moved: string[] = [];\n try {\n for (const name of children) { await rename(join(root, name), join(staging, name)); moved.push(name); }\n await rename(staging, join(root, 'data'));\n } catch (error) {\n for (const name of moved.reverse()) await rename(join(staging, name), join(root, name));\n await rm(staging, { recursive: true, force: true });\n throw error;\n }\n await chmod(join(root, 'data'), originalMode);\n const { bytes, files } = await makeManifests(root, { ...options, checksums: algorithms });\n await writeFile(join(root, 'bagit.txt'), BAG_DECLARATION);\n await writeFile(join(root, 'bag-info.txt'), serializeTagFile(makeBagInfo(options.bagInfo, bytes, files)));\n await makeTagManifests(root, algorithms, 'utf-8', options.signal);\n return new Bag(root);\n}\n\nexport async function makeManifests(root: string, options: Pick<MakeBagOptions, 'checksums' | 'concurrency' | 'signal'> = {}, encoding = 'utf-8'): Promise<{ bytes: bigint; files: number }> {\n const algorithms = algorithmsFor(options.checksums);\n const filenames = [...walkFiles(join(root, 'data'), 'data/')];\n buildUnicodeNormalizedLookupDict(filenames);\n const records = await mapConcurrent(filenames, options.concurrency ?? 1, async filename => {\n assertSafePath(root, filename);\n return { filename, ...await hashFile(join(root, filename), algorithms, options.signal) };\n });\n for (const a of algorithms) {\n const text = records.map(r => `${r.hashes[a]} ${encodeFilename(r.filename)}\\n`).join('');\n await writeFile(join(root, `manifest-${a}.txt`), encodeText(text, encoding));\n }\n return { bytes: records.reduce((sum, r) => sum + r.bytes, 0n), files: records.length };\n}\n\nexport async function makeTagManifests(root: string, algorithms: readonly string[] = DEFAULT_CHECKSUMS, encoding = 'utf-8', signal?: AbortSignal): Promise<void> {\n const tagFiles = [...walkFiles(root)].filter(f => !f.startsWith('data/') && !basename(f).startsWith('tagmanifest-'));\n const records = [];\n for (const filename of tagFiles) {\n assertSafePath(root, filename);\n records.push({ filename, ...await hashFile(join(root, filename), algorithms, signal) });\n }\n for (const a of algorithmsFor(algorithms)) {\n await writeFile(join(root, `tagmanifest-${a}.txt`), encodeText(records.map(r => `${r.hashes[a]} ${encodeFilename(r.filename)}\\n`).join(''), encoding));\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class BagError extends Error {
|
|
2
|
+
constructor(message: string, options?: ErrorOptions);
|
|
3
|
+
toString(): string;
|
|
4
|
+
}
|
|
5
|
+
export declare class ManifestErrorDetail extends BagError {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
constructor(path: string, message?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class ChecksumMismatch extends ManifestErrorDetail {
|
|
10
|
+
readonly algorithm: string;
|
|
11
|
+
readonly expected: string;
|
|
12
|
+
readonly found: string;
|
|
13
|
+
constructor(path: string, algorithm: string, expected: string, found: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class FileMissing extends ManifestErrorDetail {
|
|
16
|
+
constructor(path: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class UnexpectedFile extends ManifestErrorDetail {
|
|
19
|
+
constructor(path: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class BagValidationError extends BagError {
|
|
22
|
+
readonly details: ManifestErrorDetail[];
|
|
23
|
+
constructor(message: string, details?: ManifestErrorDetail[], options?: ErrorOptions);
|
|
24
|
+
}
|
|
25
|
+
export declare class FileNormalizationConflict extends BagError {
|
|
26
|
+
readonly fileA: string;
|
|
27
|
+
readonly fileB: string;
|
|
28
|
+
constructor(fileA: string, fileB: string);
|
|
29
|
+
get file_a(): string;
|
|
30
|
+
get file_b(): string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAI1C,QAAQ,IAAI,MAAM;CAC5B;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;aACnB,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EAAE,OAAO,SAAO;CACzD;AAED,qBAAa,gBAAiB,SAAQ,mBAAmB;aACb,SAAS,EAAE,MAAM;aAAkB,QAAQ,EAAE,MAAM;aAAkB,KAAK,EAAE,MAAM;gBAAhH,IAAI,EAAE,MAAM,EAAkB,SAAS,EAAE,MAAM,EAAkB,QAAQ,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM;CAG7H;AAED,qBAAa,WAAY,SAAQ,mBAAmB;gBACtC,IAAI,EAAE,MAAM;CACzB;AAED,qBAAa,cAAe,SAAQ,mBAAmB;gBACzC,IAAI,EAAE,MAAM;CACzB;AAED,qBAAa,kBAAmB,SAAQ,QAAQ;aACD,OAAO,EAAE,mBAAmB,EAAE;gBAA/D,OAAO,EAAE,MAAM,EAAkB,OAAO,GAAE,mBAAmB,EAAO,EAAE,OAAO,CAAC,EAAE,YAAY;CAGzG;AAED,qBAAa,yBAA0B,SAAQ,QAAQ;aACzB,KAAK,EAAE,MAAM;aAAkB,KAAK,EAAE,MAAM;gBAA5C,KAAK,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM;IAGxE,IAAI,MAAM,IAAI,MAAM,CAAuB;IAC3C,IAAI,MAAM,IAAI,MAAM,CAAuB;CAC5C"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export class BagError extends Error {
|
|
2
|
+
constructor(message, options) {
|
|
3
|
+
super(message, options);
|
|
4
|
+
this.name = new.target.name;
|
|
5
|
+
}
|
|
6
|
+
toString() { return this.message; }
|
|
7
|
+
}
|
|
8
|
+
export class ManifestErrorDetail extends BagError {
|
|
9
|
+
path;
|
|
10
|
+
constructor(path, message = path) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.path = path;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class ChecksumMismatch extends ManifestErrorDetail {
|
|
16
|
+
algorithm;
|
|
17
|
+
expected;
|
|
18
|
+
found;
|
|
19
|
+
constructor(path, algorithm, expected, found) {
|
|
20
|
+
super(path, `${path} ${algorithm} validation failed: expected="${expected}" found="${found}"`);
|
|
21
|
+
this.algorithm = algorithm;
|
|
22
|
+
this.expected = expected;
|
|
23
|
+
this.found = found;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class FileMissing extends ManifestErrorDetail {
|
|
27
|
+
constructor(path) { super(path, `${path} exists in manifest but was not found on filesystem`); }
|
|
28
|
+
}
|
|
29
|
+
export class UnexpectedFile extends ManifestErrorDetail {
|
|
30
|
+
constructor(path) { super(path, `${path} exists on filesystem but is not in the manifest`); }
|
|
31
|
+
}
|
|
32
|
+
export class BagValidationError extends BagError {
|
|
33
|
+
details;
|
|
34
|
+
constructor(message, details = [], options) {
|
|
35
|
+
super(details.length ? `${message}: ${details.join('; ')}` : message, options);
|
|
36
|
+
this.details = details;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class FileNormalizationConflict extends BagError {
|
|
40
|
+
fileA;
|
|
41
|
+
fileB;
|
|
42
|
+
constructor(fileA, fileB) {
|
|
43
|
+
super(`Unicode normalization conflict for file "${fileA}" and "${fileB}"`);
|
|
44
|
+
this.fileA = fileA;
|
|
45
|
+
this.fileB = fileB;
|
|
46
|
+
}
|
|
47
|
+
get file_a() { return this.fileA; }
|
|
48
|
+
get file_b() { return this.fileB; }
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EA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O,GAAP,OAAO,CAA4B;IAEhF,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,QAAQ;IACzB;IAA+B;IAA3D,YAA4B,KAAa,EAAkB,KAAa;QACtE,KAAK,CAAC,4CAA4C,KAAK,UAAU,KAAK,GAAG,CAAC,CAAC;QADjD,UAAK,GAAL,KAAK,CAAQ;QAAkB,UAAK,GAAL,KAAK,CAAQ;IAExE,CAAC;IACD,IAAI,MAAM,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;CAC5C","sourcesContent":["export class BagError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n override toString(): string { return this.message; }\n}\n\nexport class ManifestErrorDetail extends BagError {\n constructor(public readonly path: string, message = path) { super(message); }\n}\n\nexport class ChecksumMismatch extends ManifestErrorDetail {\n constructor(path: string, public readonly algorithm: string, public readonly expected: string, public readonly found: string) {\n super(path, `${path} ${algorithm} validation failed: expected=\"${expected}\" found=\"${found}\"`);\n }\n}\n\nexport class FileMissing extends ManifestErrorDetail {\n constructor(path: string) { super(path, `${path} exists in manifest but was not found on filesystem`); }\n}\n\nexport class UnexpectedFile extends ManifestErrorDetail {\n constructor(path: string) { super(path, `${path} exists on filesystem but is not in the manifest`); }\n}\n\nexport class BagValidationError extends BagError {\n constructor(message: string, public readonly details: ManifestErrorDetail[] = [], options?: ErrorOptions) {\n super(details.length ? `${message}: ${details.join('; ')}` : message, options);\n }\n}\n\nexport class FileNormalizationConflict extends BagError {\n constructor(public readonly fileA: string, public readonly fileB: string) {\n super(`Unicode normalization conflict for file \"${fileA}\" and \"${fileB}\"`);\n }\n get file_a(): string { return this.fileA; }\n get file_b(): string { return this.fileB; }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Bag, makeBag, makeManifests, makeTagManifests, makeBag as make_bag } from './bag.js';
|
|
2
|
+
export { BagError, BagValidationError, ManifestErrorDetail, ChecksumMismatch, FileMissing, UnexpectedFile, FileNormalizationConflict } from './errors.js';
|
|
3
|
+
export { createBagZipStream, createBagZipStreamFromEntries, folderToBagZip, folderToBagitZip, type BagZipOptions, type BagZipEntry, type BagZipProgress, type BagZipResult, } from './zip.js';
|
|
4
|
+
export { VERSION, DEFAULT_CHECKSUMS, CHECKSUM_ALGOS, HASH_BLOCK_SIZE, BAG_DECLARATION, STANDARD_BAG_INFO_HEADERS, normalizeUnicode, buildUnicodeNormalizedLookupDict, encodeFilename, decodeFilename, parseTagFile, serializeTagFile, loadTagFile, getHashers, generateManifestLines, } from './util.js';
|
|
5
|
+
export type { BagInfo, BagInfoInput, TagValue, Checksums, Entries, FetchEntry, MakeBagOptions, ValidationOptions, SaveOptions } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC1J,OAAO,EACL,kBAAkB,EAAE,6BAA6B,EAAE,cAAc,EAAE,gBAAgB,EACnF,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,GAC7E,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,yBAAyB,EACvG,gBAAgB,EAAE,gCAAgC,EAAE,cAAc,EAAE,cAAc,EAClF,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,GAC/E,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Bag, makeBag, makeManifests, makeTagManifests, makeBag as make_bag } from './bag.js';
|
|
2
|
+
export { BagError, BagValidationError, ManifestErrorDetail, ChecksumMismatch, FileMissing, UnexpectedFile, FileNormalizationConflict } from './errors.js';
|
|
3
|
+
export { createBagZipStream, createBagZipStreamFromEntries, folderToBagZip, folderToBagitZip, } from './zip.js';
|
|
4
|
+
export { VERSION, DEFAULT_CHECKSUMS, CHECKSUM_ALGOS, HASH_BLOCK_SIZE, BAG_DECLARATION, STANDARD_BAG_INFO_HEADERS, normalizeUnicode, buildUnicodeNormalizedLookupDict, encodeFilename, decodeFilename, parseTagFile, serializeTagFile, loadTagFile, getHashers, generateManifestLines, } from './util.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC1J,OAAO,EACL,kBAAkB,EAAE,6BAA6B,EAAE,cAAc,EAAE,gBAAgB,GAEpF,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,yBAAyB,EACvG,gBAAgB,EAAE,gCAAgC,EAAE,cAAc,EAAE,cAAc,EAClF,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,GAC/E,MAAM,WAAW,CAAC","sourcesContent":["export { Bag, makeBag, makeManifests, makeTagManifests, makeBag as make_bag } from './bag.js';\nexport { BagError, BagValidationError, ManifestErrorDetail, ChecksumMismatch, FileMissing, UnexpectedFile, FileNormalizationConflict } from './errors.js';\nexport {\n createBagZipStream, createBagZipStreamFromEntries, folderToBagZip, folderToBagitZip,\n type BagZipOptions, type BagZipEntry, type BagZipProgress, type BagZipResult,\n} from './zip.js';\nexport {\n VERSION, DEFAULT_CHECKSUMS, CHECKSUM_ALGOS, HASH_BLOCK_SIZE, BAG_DECLARATION, STANDARD_BAG_INFO_HEADERS,\n normalizeUnicode, buildUnicodeNormalizedLookupDict, encodeFilename, decodeFilename,\n parseTagFile, serializeTagFile, loadTagFile, getHashers, generateManifestLines,\n} from './util.js';\nexport type { BagInfo, BagInfoInput, TagValue, Checksums, Entries, FetchEntry, MakeBagOptions, ValidationOptions, SaveOptions } from './types.js';\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type TagValue = string | string[];
|
|
2
|
+
export type BagInfo = Record<string, TagValue>;
|
|
3
|
+
export type BagInfoInput = Record<string, string | number | boolean | readonly (string | number | boolean)[]>;
|
|
4
|
+
export type Checksums = Record<string, string>;
|
|
5
|
+
export type Entries = Record<string, Checksums>;
|
|
6
|
+
export interface MakeBagOptions {
|
|
7
|
+
bagInfo?: BagInfoInput;
|
|
8
|
+
checksums?: readonly string[];
|
|
9
|
+
/** Tag files written by this library use UTF-8. */
|
|
10
|
+
encoding?: 'utf-8' | 'UTF-8';
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
/** Maximum simultaneous file reads. */
|
|
13
|
+
concurrency?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ValidationOptions {
|
|
16
|
+
fast?: boolean;
|
|
17
|
+
completenessOnly?: boolean;
|
|
18
|
+
/** Alias for Python callers. */
|
|
19
|
+
completeness_only?: boolean;
|
|
20
|
+
concurrency?: number;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export interface SaveOptions {
|
|
24
|
+
manifests?: boolean;
|
|
25
|
+
concurrency?: number;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}
|
|
28
|
+
export type FetchEntry = [url: string, size: string, filename: string];
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AACzC,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC/C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC9G,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gCAAgC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type TagValue = string | string[];\nexport type BagInfo = Record<string, TagValue>;\nexport type BagInfoInput = Record<string, string | number | boolean | readonly (string | number | boolean)[]>;\nexport type Checksums = Record<string, string>;\nexport type Entries = Record<string, Checksums>;\n\nexport interface MakeBagOptions {\n bagInfo?: BagInfoInput;\n checksums?: readonly string[];\n /** Tag files written by this library use UTF-8. */\n encoding?: 'utf-8' | 'UTF-8';\n signal?: AbortSignal;\n /** Maximum simultaneous file reads. */\n concurrency?: number;\n}\n\nexport interface ValidationOptions {\n fast?: boolean;\n completenessOnly?: boolean;\n /** Alias for Python callers. */\n completeness_only?: boolean;\n concurrency?: number;\n signal?: AbortSignal;\n}\n\nexport interface SaveOptions {\n manifests?: boolean;\n concurrency?: number;\n signal?: AbortSignal;\n}\n\nexport type FetchEntry = [url: string, size: string, filename: string];\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Hash } from 'node:crypto';
|
|
2
|
+
import type { BagInfo, BagInfoInput, Checksums } from './types.js';
|
|
3
|
+
export declare const VERSION = "1.1.0";
|
|
4
|
+
export declare const DEFAULT_CHECKSUMS: readonly string[];
|
|
5
|
+
export declare const HASH_BLOCK_SIZE: number;
|
|
6
|
+
export declare const BAG_DECLARATION = "BagIt-Version: 1.0\nTag-File-Character-Encoding: UTF-8\n";
|
|
7
|
+
export declare const STANDARD_BAG_INFO_HEADERS: readonly string[];
|
|
8
|
+
export declare const CHECKSUM_ALGOS: readonly string[];
|
|
9
|
+
export declare function getHashers(algorithms: readonly string[]): Record<string, Hash>;
|
|
10
|
+
export declare function algorithmsFor(algorithms?: readonly string[]): string[];
|
|
11
|
+
export declare function digestBytes(bytes: Uint8Array, algorithms: readonly string[]): Checksums;
|
|
12
|
+
export declare function hashFile(path: string, algorithms: readonly string[], signal?: AbortSignal): Promise<{
|
|
13
|
+
hashes: Checksums;
|
|
14
|
+
bytes: bigint;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function generateManifestLines(filename: string, algorithms?: readonly string[], signal?: AbortSignal): Promise<[algorithm: string, digest: string, filename: string, bytes: bigint][]>;
|
|
17
|
+
export declare const normalizeUnicode: (s: string) => string;
|
|
18
|
+
export declare function buildUnicodeNormalizedLookupDict(filenames: Iterable<string>): Record<string, string>;
|
|
19
|
+
export declare const encodeFilename: (s: string) => string;
|
|
20
|
+
export declare const decodeFilename: (s: string) => string;
|
|
21
|
+
export declare const posixPath: (s: string) => string;
|
|
22
|
+
export declare const isFile: (p: string) => boolean;
|
|
23
|
+
export declare const isDirectory: (p: string) => boolean;
|
|
24
|
+
/** Match os.walk: sorted files at each level, then sorted directories; do not follow directory symlinks. */
|
|
25
|
+
export declare function walkFiles(root: string, prefix?: string): Generator<string>;
|
|
26
|
+
export declare function compareNames(a: string, b: string): number;
|
|
27
|
+
export declare function pathIsDangerous(root: string, filename: string): boolean;
|
|
28
|
+
export declare function assertSafePath(root: string, filename: string, context?: string): void;
|
|
29
|
+
export declare function decodeText(bytes: Uint8Array, encoding?: string): string;
|
|
30
|
+
export declare function checkEncoding(encoding: string): void;
|
|
31
|
+
export declare function encodeText(text: string, encoding?: string): Buffer;
|
|
32
|
+
export declare function parseTagFile(text: string, filename?: string): BagInfo;
|
|
33
|
+
export declare function serializeTagFile(info: BagInfoInput): string;
|
|
34
|
+
export declare function makeBagInfo(info: BagInfoInput | undefined, bytes: bigint, files: number): BagInfo;
|
|
35
|
+
export declare function loadTagFile(path: string, encoding?: string): Promise<BagInfo>;
|
|
36
|
+
export declare function checkPermissions(root: string, saving?: boolean): void;
|
|
37
|
+
export declare function checkConcurrency(concurrency?: number): number;
|
|
38
|
+
export declare function mapConcurrent<T, R>(items: readonly T[], concurrency: number, fn: (value: T) => Promise<R>): Promise<R[]>;
|
|
39
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAKpD,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnE,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAwC,CAAC;AACxF,eAAO,MAAM,eAAe,QAAa,CAAC;AAC1C,eAAO,MAAM,eAAe,6DAA6D,CAAC;AAC1F,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAIrD,CAAC;AAMH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAG1C,CAAC;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAQ9E;AACD,wBAAgB,aAAa,CAAC,UAAU,GAAE,SAAS,MAAM,EAAsB,GAAG,MAAM,EAAE,CAEzF;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAEvF;AACD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,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