@storyteller-platform/audiobook 0.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.
@@ -0,0 +1,128 @@
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 Uint8ArrayFileAbstraction_exports = {};
20
+ __export(Uint8ArrayFileAbstraction_exports, {
21
+ Uint8ArrayFileAbstraction: () => Uint8ArrayFileAbstraction,
22
+ Uint8ArrayStream: () => Uint8ArrayStream
23
+ });
24
+ module.exports = __toCommonJS(Uint8ArrayFileAbstraction_exports);
25
+ var import_node_taglib_sharp = require("node-taglib-sharp");
26
+ class Uint8ArrayStream {
27
+ constructor(fileAbstraction, canWrite) {
28
+ this.fileAbstraction = fileAbstraction;
29
+ this.canWrite = canWrite;
30
+ this.length = fileAbstraction.data.length;
31
+ }
32
+ position = 0;
33
+ length;
34
+ read(buffer, bufferOffset, length) {
35
+ const availableBytes = this.fileAbstraction.data.length - this.position;
36
+ const bytesToRead = Math.min(length, availableBytes);
37
+ if (bytesToRead <= 0) {
38
+ return 0;
39
+ }
40
+ buffer.set(
41
+ this.fileAbstraction.data.subarray(
42
+ this.position,
43
+ this.position + bytesToRead
44
+ ),
45
+ bufferOffset
46
+ );
47
+ this.position += bytesToRead;
48
+ return bytesToRead;
49
+ }
50
+ seek(offset, origin) {
51
+ switch (origin) {
52
+ case import_node_taglib_sharp.SeekOrigin.Begin:
53
+ this.position = offset;
54
+ break;
55
+ case import_node_taglib_sharp.SeekOrigin.Current:
56
+ this.position += offset;
57
+ break;
58
+ case import_node_taglib_sharp.SeekOrigin.End:
59
+ this.position = this.length + offset;
60
+ break;
61
+ }
62
+ }
63
+ setLength(length) {
64
+ if (!this.canWrite) {
65
+ throw new Error("Invalid operation: this stream is a read-only stream");
66
+ }
67
+ if (length === this.length) {
68
+ return;
69
+ }
70
+ const newData = new Uint8Array(length);
71
+ if (length > 0) {
72
+ const bytesToCopy = Math.min(this.fileAbstraction.data.length, length);
73
+ newData.set(this.fileAbstraction.data.subarray(0, bytesToCopy));
74
+ }
75
+ this.fileAbstraction.data = newData;
76
+ if (this.position > length) {
77
+ this.position = length;
78
+ }
79
+ this.length = length;
80
+ }
81
+ write(buffer, bufferOffset, length) {
82
+ if (buffer instanceof import_node_taglib_sharp.ByteVector) {
83
+ buffer = buffer.toByteArray();
84
+ }
85
+ if (!this.canWrite) {
86
+ throw new Error("Invalid operation: this stream is a read-only stream");
87
+ }
88
+ const bytesToWrite = Math.min(buffer.length - bufferOffset, length);
89
+ const originalLength = this.length;
90
+ if (this.position + bytesToWrite > originalLength) {
91
+ this.setLength(this.position + bytesToWrite);
92
+ }
93
+ this.fileAbstraction.data.set(
94
+ buffer.subarray(bufferOffset, bytesToWrite),
95
+ this.position
96
+ );
97
+ this.position += bytesToWrite;
98
+ return bytesToWrite;
99
+ }
100
+ close() {
101
+ }
102
+ static createAsRead(fileAbstraction) {
103
+ return new Uint8ArrayStream(fileAbstraction, false);
104
+ }
105
+ static createAsReadWrite(fileAbstraction) {
106
+ return new Uint8ArrayStream(fileAbstraction, true);
107
+ }
108
+ }
109
+ class Uint8ArrayFileAbstraction {
110
+ constructor(name, data) {
111
+ this.name = name;
112
+ this.data = data;
113
+ }
114
+ get readStream() {
115
+ return Uint8ArrayStream.createAsRead(this);
116
+ }
117
+ get writeStream() {
118
+ return Uint8ArrayStream.createAsReadWrite(this);
119
+ }
120
+ closeStream(stream) {
121
+ stream.close();
122
+ }
123
+ }
124
+ // Annotate the CommonJS export names for ESM import in node:
125
+ 0 && (module.exports = {
126
+ Uint8ArrayFileAbstraction,
127
+ Uint8ArrayStream
128
+ });
@@ -0,0 +1,26 @@
1
+ import { IStream, IFileAbstraction, SeekOrigin } from 'node-taglib-sharp';
2
+
3
+ declare class Uint8ArrayStream implements IStream {
4
+ private fileAbstraction;
5
+ canWrite: boolean;
6
+ position: number;
7
+ length: number;
8
+ constructor(fileAbstraction: Uint8ArrayFileAbstraction, canWrite: boolean);
9
+ read(buffer: Uint8Array, bufferOffset: number, length: number): number;
10
+ seek(offset: number, origin: SeekOrigin): void;
11
+ setLength(length: number): void;
12
+ write(buffer: Uint8Array, bufferOffset: number, length: number): number;
13
+ close(): void;
14
+ static createAsRead(fileAbstraction: Uint8ArrayFileAbstraction): Uint8ArrayStream;
15
+ static createAsReadWrite(fileAbstraction: Uint8ArrayFileAbstraction): Uint8ArrayStream;
16
+ }
17
+ declare class Uint8ArrayFileAbstraction implements IFileAbstraction {
18
+ name: string;
19
+ data: Uint8Array;
20
+ constructor(name: string, data: Uint8Array);
21
+ get readStream(): IStream;
22
+ get writeStream(): IStream;
23
+ closeStream(stream: IStream): void;
24
+ }
25
+
26
+ export { Uint8ArrayFileAbstraction, Uint8ArrayStream };
@@ -0,0 +1,26 @@
1
+ import { IStream, IFileAbstraction, SeekOrigin } from 'node-taglib-sharp';
2
+
3
+ declare class Uint8ArrayStream implements IStream {
4
+ private fileAbstraction;
5
+ canWrite: boolean;
6
+ position: number;
7
+ length: number;
8
+ constructor(fileAbstraction: Uint8ArrayFileAbstraction, canWrite: boolean);
9
+ read(buffer: Uint8Array, bufferOffset: number, length: number): number;
10
+ seek(offset: number, origin: SeekOrigin): void;
11
+ setLength(length: number): void;
12
+ write(buffer: Uint8Array, bufferOffset: number, length: number): number;
13
+ close(): void;
14
+ static createAsRead(fileAbstraction: Uint8ArrayFileAbstraction): Uint8ArrayStream;
15
+ static createAsReadWrite(fileAbstraction: Uint8ArrayFileAbstraction): Uint8ArrayStream;
16
+ }
17
+ declare class Uint8ArrayFileAbstraction implements IFileAbstraction {
18
+ name: string;
19
+ data: Uint8Array;
20
+ constructor(name: string, data: Uint8Array);
21
+ get readStream(): IStream;
22
+ get writeStream(): IStream;
23
+ closeStream(stream: IStream): void;
24
+ }
25
+
26
+ export { Uint8ArrayFileAbstraction, Uint8ArrayStream };
@@ -0,0 +1,106 @@
1
+ import {
2
+ ByteVector,
3
+ SeekOrigin
4
+ } from "node-taglib-sharp";
5
+ class Uint8ArrayStream {
6
+ constructor(fileAbstraction, canWrite) {
7
+ this.fileAbstraction = fileAbstraction;
8
+ this.canWrite = canWrite;
9
+ this.length = fileAbstraction.data.length;
10
+ }
11
+ position = 0;
12
+ length;
13
+ read(buffer, bufferOffset, length) {
14
+ const availableBytes = this.fileAbstraction.data.length - this.position;
15
+ const bytesToRead = Math.min(length, availableBytes);
16
+ if (bytesToRead <= 0) {
17
+ return 0;
18
+ }
19
+ buffer.set(
20
+ this.fileAbstraction.data.subarray(
21
+ this.position,
22
+ this.position + bytesToRead
23
+ ),
24
+ bufferOffset
25
+ );
26
+ this.position += bytesToRead;
27
+ return bytesToRead;
28
+ }
29
+ seek(offset, origin) {
30
+ switch (origin) {
31
+ case SeekOrigin.Begin:
32
+ this.position = offset;
33
+ break;
34
+ case SeekOrigin.Current:
35
+ this.position += offset;
36
+ break;
37
+ case SeekOrigin.End:
38
+ this.position = this.length + offset;
39
+ break;
40
+ }
41
+ }
42
+ setLength(length) {
43
+ if (!this.canWrite) {
44
+ throw new Error("Invalid operation: this stream is a read-only stream");
45
+ }
46
+ if (length === this.length) {
47
+ return;
48
+ }
49
+ const newData = new Uint8Array(length);
50
+ if (length > 0) {
51
+ const bytesToCopy = Math.min(this.fileAbstraction.data.length, length);
52
+ newData.set(this.fileAbstraction.data.subarray(0, bytesToCopy));
53
+ }
54
+ this.fileAbstraction.data = newData;
55
+ if (this.position > length) {
56
+ this.position = length;
57
+ }
58
+ this.length = length;
59
+ }
60
+ write(buffer, bufferOffset, length) {
61
+ if (buffer instanceof ByteVector) {
62
+ buffer = buffer.toByteArray();
63
+ }
64
+ if (!this.canWrite) {
65
+ throw new Error("Invalid operation: this stream is a read-only stream");
66
+ }
67
+ const bytesToWrite = Math.min(buffer.length - bufferOffset, length);
68
+ const originalLength = this.length;
69
+ if (this.position + bytesToWrite > originalLength) {
70
+ this.setLength(this.position + bytesToWrite);
71
+ }
72
+ this.fileAbstraction.data.set(
73
+ buffer.subarray(bufferOffset, bytesToWrite),
74
+ this.position
75
+ );
76
+ this.position += bytesToWrite;
77
+ return bytesToWrite;
78
+ }
79
+ close() {
80
+ }
81
+ static createAsRead(fileAbstraction) {
82
+ return new Uint8ArrayStream(fileAbstraction, false);
83
+ }
84
+ static createAsReadWrite(fileAbstraction) {
85
+ return new Uint8ArrayStream(fileAbstraction, true);
86
+ }
87
+ }
88
+ class Uint8ArrayFileAbstraction {
89
+ constructor(name, data) {
90
+ this.name = name;
91
+ this.data = data;
92
+ }
93
+ get readStream() {
94
+ return Uint8ArrayStream.createAsRead(this);
95
+ }
96
+ get writeStream() {
97
+ return Uint8ArrayStream.createAsReadWrite(this);
98
+ }
99
+ closeStream(stream) {
100
+ stream.close();
101
+ }
102
+ }
103
+ export {
104
+ Uint8ArrayFileAbstraction,
105
+ Uint8ArrayStream
106
+ };
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@storyteller-platform/audiobook",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "@storyteller": "./src/index.ts",
11
+ "@storyteller-node": "./src/node/index.ts",
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "./node": {
22
+ "@storyteller": "./src/node/index.ts",
23
+ "@storyteller-node": "./src/node/index.ts",
24
+ "import": {
25
+ "types": "./dist/node/index.d.ts",
26
+ "default": "./dist/node/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/node/index.d.cts",
30
+ "default": "./dist/node/index.cjs"
31
+ }
32
+ }
33
+ },
34
+ "files": [
35
+ "dist/"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "readme:toc": "markdown-toc --maxdepth=5 --append='\n- [API Docs](#api-docs)' --bullets='-' -i readme-stub.md",
40
+ "readme:api": "typedoc",
41
+ "readme": "yarn readme:api && yarn readme:toc && cat readme-stub.md > README.md && tail -n +2 gen/node.md >> README.md && tail -n +2 gen/entry.md >> README.md && tail -n +2 gen/base.md >> README.md && tail -n +2 gen/node/entry.md >> README.md",
42
+ "test": "rm -rf src/__fixtures__/__output__ && tsx -C @storyteller --test src/**/*.test.ts",
43
+ "test:watch": "tsx --test --watch -C @storyteller --test src/**/*.test.ts",
44
+ "prepack": "yarn build"
45
+ },
46
+ "devDependencies": {
47
+ "@storyteller-platform/tsup": "^0.1.0",
48
+ "@tsconfig/strictest": "^2.0.5",
49
+ "@types/mime-types": "^2",
50
+ "@types/node": "^22.10.1",
51
+ "markdown-toc": "^1.2.0",
52
+ "remark-toc": "^9.0.0",
53
+ "tsup": "^8.5.0",
54
+ "tsx": "^4.19.2",
55
+ "typedoc": "^0.28.4",
56
+ "typedoc-plugin-markdown": "^4.6.3",
57
+ "typedoc-plugin-remark": "^1.2.0",
58
+ "typescript": "^5.8.3"
59
+ },
60
+ "dependencies": {
61
+ "@einheit/path-resolve": "^1.2.0",
62
+ "@storyteller-platform/fs": "^0.1.2",
63
+ "@storyteller-platform/path": "^0.1.0",
64
+ "@zip.js/zip.js": "^2.7.71",
65
+ "async-mutex": "^0.5.0",
66
+ "fast-xml-parser": "^4.0.0",
67
+ "mem": "^8.0.0",
68
+ "mime-types": "^3.0.1",
69
+ "nanoid": "^5.1.5",
70
+ "node-taglib-sharp": "^6.0.1"
71
+ },
72
+ "publishConfig": {
73
+ "access": "public"
74
+ }
75
+ }