@storyteller-platform/epub 0.7.1 → 0.8.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/dist/zip.cjs DELETED
@@ -1,142 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var zip_exports = {};
20
- __export(zip_exports, {
21
- openZip: () => openZip
22
- });
23
- module.exports = __toCommonJS(zip_exports);
24
- var import_node_fs = require("node:fs");
25
- var import_promises = require("node:fs/promises");
26
- var import_yauzl_promise = require("yauzl-promise");
27
- const EOCDR_SIGNATURE = Buffer.from([80, 75, 5, 6]);
28
- const EOCDR_SIZE = 22;
29
- const MAX_TAIL_SCAN = 1024 * 1024;
30
- function toBuffer(source) {
31
- return Buffer.isBuffer(source) ? source : Buffer.from(source.buffer, source.byteOffset, source.byteLength);
32
- }
33
- function findArchiveEnd(tail, tailStart, fileSize) {
34
- let searchFrom = tail.length - EOCDR_SIZE;
35
- while (searchFrom >= 0) {
36
- const index = tail.lastIndexOf(EOCDR_SIGNATURE, searchFrom);
37
- if (index === -1) return null;
38
- const commentLength = tail.readUInt16LE(index + 20);
39
- const end = tailStart + index + EOCDR_SIZE + commentLength;
40
- if (end < fileSize) return end;
41
- searchFrom = index - 1;
42
- }
43
- return null;
44
- }
45
- async function readExactly(handle, length, position) {
46
- const buffer = Buffer.allocUnsafe(length);
47
- let offset = 0;
48
- while (offset < length) {
49
- const { bytesRead } = await handle.read(
50
- buffer,
51
- offset,
52
- length - offset,
53
- position + offset
54
- );
55
- if (bytesRead === 0) return null;
56
- offset += bytesRead;
57
- }
58
- return buffer;
59
- }
60
- async function findFileArchiveEnd(path) {
61
- let handle;
62
- try {
63
- handle = await (0, import_promises.open)(path, "r");
64
- } catch {
65
- return null;
66
- }
67
- try {
68
- const { size } = await handle.stat();
69
- const tailLength = Math.min(size, MAX_TAIL_SCAN);
70
- if (tailLength < EOCDR_SIZE) return null;
71
- const tailStart = size - tailLength;
72
- const tail = await readExactly(handle, tailLength, tailStart);
73
- if (!tail) return null;
74
- return findArchiveEnd(tail, tailStart, size);
75
- } finally {
76
- await handle.close();
77
- }
78
- }
79
- class TruncatedFileReader extends import_yauzl_promise.Reader {
80
- constructor(path) {
81
- super();
82
- this.path = path;
83
- }
84
- handle = null;
85
- async _open() {
86
- this.handle = await (0, import_promises.open)(this.path, "r");
87
- return {};
88
- }
89
- async _close() {
90
- const handle = this.handle;
91
- this.handle = null;
92
- if (handle) await handle.close();
93
- return {};
94
- }
95
- async _read(start, length) {
96
- if (!this.handle) throw new Error(`reader for ${this.path} is not open`);
97
- const buffer = await readExactly(this.handle, length, start);
98
- if (!buffer) {
99
- throw new Error(`unexpected end of file reading ${this.path}`);
100
- }
101
- return buffer;
102
- }
103
- _createReadStream(start, length) {
104
- return (0, import_node_fs.createReadStream)(this.path, { start, end: start + length - 1 });
105
- }
106
- }
107
- async function openBufferZip(data) {
108
- try {
109
- return await (0, import_yauzl_promise.fromBuffer)(data);
110
- } catch (error) {
111
- const tailStart = Math.max(0, data.length - MAX_TAIL_SCAN);
112
- const end = findArchiveEnd(data.subarray(tailStart), tailStart, data.length);
113
- if (end === null) throw error;
114
- try {
115
- return await (0, import_yauzl_promise.fromBuffer)(data.subarray(0, end));
116
- } catch {
117
- throw error;
118
- }
119
- }
120
- }
121
- async function openFileZip(path) {
122
- try {
123
- return await (0, import_yauzl_promise.open)(path);
124
- } catch (error) {
125
- const end = await findFileArchiveEnd(path);
126
- if (end === null) throw error;
127
- const reader = new TruncatedFileReader(path);
128
- try {
129
- return await (0, import_yauzl_promise.fromReader)(reader, end);
130
- } catch {
131
- await reader._close().catch(() => void 0);
132
- throw error;
133
- }
134
- }
135
- }
136
- async function openZip(source) {
137
- return typeof source === "string" ? openFileZip(source) : openBufferZip(toBuffer(source));
138
- }
139
- // Annotate the CommonJS export names for ESM import in node:
140
- 0 && (module.exports = {
141
- openZip
142
- });
package/dist/zip.d.cts DELETED
@@ -1,5 +0,0 @@
1
- import { ZipFile } from 'yauzl-promise';
2
-
3
- declare function openZip(source: string | Uint8Array): Promise<ZipFile>;
4
-
5
- export { openZip };