byte-codec 1.0.3 → 1.0.4
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/package.json +30 -11
- package/dist/index-DCdK98vS.d.cts +0 -81
- package/dist/index-DCdK98vS.d.ts +0 -81
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joseph Mearman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "byte-codec",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Generic byte-level primitives (ByteWriter, ByteReader, CRC-32, deflate/inflate) and PNG/JPEG image encoding/decoding with zero PDF knowledge — the shared utility package for the documents.js family.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -30,24 +30,37 @@
|
|
|
30
30
|
"require": "./dist/*.cjs"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"module": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true,
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
33
48
|
"scripts": {
|
|
34
|
-
"build": "tsdown
|
|
35
|
-
"
|
|
49
|
+
"build": "tsdown",
|
|
50
|
+
"prepublishOnly": "pnpm run lint && pnpm run typecheck && tsdown && publint && attw --pack",
|
|
36
51
|
"lint": "eslint . --fix --cache --max-warnings 0",
|
|
52
|
+
"lint:check": "eslint . --max-warnings 0",
|
|
53
|
+
"typecheck": "tsc --noEmit",
|
|
37
54
|
"test": "vitest run",
|
|
38
55
|
"test:watch": "vitest",
|
|
39
|
-
"prepare": "husky"
|
|
40
|
-
"prepublishOnly": "pnpm run build",
|
|
41
|
-
"lint:check": "eslint . --max-warnings 0"
|
|
56
|
+
"prepare": "husky"
|
|
42
57
|
},
|
|
43
|
-
"files": [
|
|
44
|
-
"dist"
|
|
45
|
-
],
|
|
46
58
|
"packageManager": "pnpm@11.6.0",
|
|
47
59
|
"dependencies": {
|
|
48
60
|
"fflate": "^0.8.2"
|
|
49
61
|
},
|
|
50
62
|
"devDependencies": {
|
|
63
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
51
64
|
"@commitlint/cli": "^21.2.1",
|
|
52
65
|
"@commitlint/config-conventional": "^21.2.0",
|
|
53
66
|
"@eslint/js": "^10.0.1",
|
|
@@ -58,13 +71,19 @@
|
|
|
58
71
|
"globals": "^17.8.0",
|
|
59
72
|
"husky": "^9.1.7",
|
|
60
73
|
"lint-staged": "^17.2.0",
|
|
74
|
+
"publint": "^0.3.21",
|
|
61
75
|
"semantic-release": "^25.0.8",
|
|
62
|
-
"tsdown": "^0.
|
|
63
|
-
"typescript": "^
|
|
76
|
+
"tsdown": "^0.22.13",
|
|
77
|
+
"typescript": "^6.0.3",
|
|
64
78
|
"typescript-eslint": "^8.65.0",
|
|
65
79
|
"vitest": "^4.1.10"
|
|
66
80
|
},
|
|
67
81
|
"lint-staged": {
|
|
68
82
|
"*.ts": "eslint --fix"
|
|
83
|
+
},
|
|
84
|
+
"pnpm": {
|
|
85
|
+
"overrides": {
|
|
86
|
+
"rolldown": "1.2.1"
|
|
87
|
+
}
|
|
69
88
|
}
|
|
70
89
|
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
//#region src/bytes/writer.d.ts
|
|
2
|
-
declare class ByteWriter {
|
|
3
|
-
private readonly chunks;
|
|
4
|
-
private byteLength;
|
|
5
|
-
get length(): number;
|
|
6
|
-
writeBytes(bytes: Uint8Array<ArrayBuffer>): void;
|
|
7
|
-
writeByte(byte: number): void;
|
|
8
|
-
writeAscii(text: string): void;
|
|
9
|
-
toBytes(): Uint8Array<ArrayBuffer>;
|
|
10
|
-
}
|
|
11
|
-
declare function concatBytes(chunks: readonly Uint8Array<ArrayBuffer>[]): Uint8Array<ArrayBuffer>;
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/bytes/reader.d.ts
|
|
14
|
-
declare function isAsciiWhitespace(byte: number | undefined): boolean;
|
|
15
|
-
declare class ByteReader {
|
|
16
|
-
private readonly bytes;
|
|
17
|
-
private position;
|
|
18
|
-
constructor(bytes: Uint8Array<ArrayBuffer>);
|
|
19
|
-
get offset(): number;
|
|
20
|
-
get length(): number;
|
|
21
|
-
atEnd(): boolean;
|
|
22
|
-
peek(aheadBy?: number): number | undefined;
|
|
23
|
-
next(): number | undefined;
|
|
24
|
-
mark(): number;
|
|
25
|
-
reset(mark: number): void;
|
|
26
|
-
seek(offset: number): void;
|
|
27
|
-
slice(start: number, end: number): Uint8Array<ArrayBuffer>;
|
|
28
|
-
skipWhitespace(): void;
|
|
29
|
-
matchKeyword(keyword: string): boolean;
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/bytes/crc32.d.ts
|
|
33
|
-
declare function crc32(bytes: Uint8Array<ArrayBuffer>): number;
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/bytes/flate.d.ts
|
|
36
|
-
declare const MAX_INFLATE_OUTPUT_BYTES: number;
|
|
37
|
-
type DeflateLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
38
|
-
declare function deflate(data: Uint8Array<ArrayBuffer>, level?: DeflateLevel): Uint8Array<ArrayBuffer>;
|
|
39
|
-
declare function inflate(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
40
|
-
interface InflateResult {
|
|
41
|
-
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
42
|
-
readonly recovered: boolean;
|
|
43
|
-
}
|
|
44
|
-
declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/image/png-decode.d.ts
|
|
47
|
-
interface RawImage {
|
|
48
|
-
readonly width: number;
|
|
49
|
-
readonly height: number;
|
|
50
|
-
readonly channels: 1 | 3;
|
|
51
|
-
readonly data: Uint8Array<ArrayBuffer>;
|
|
52
|
-
readonly alpha?: Uint8Array<ArrayBuffer>;
|
|
53
|
-
}
|
|
54
|
-
interface PngDecodeOptions {
|
|
55
|
-
readonly onWarning?: (message: string) => void;
|
|
56
|
-
}
|
|
57
|
-
declare function decodePng(bytes: Uint8Array<ArrayBuffer>, options?: PngDecodeOptions): RawImage;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/image/png-encode.d.ts
|
|
60
|
-
interface PngEncodeOptions {
|
|
61
|
-
readonly filter?: 'none' | 'adaptive';
|
|
62
|
-
}
|
|
63
|
-
declare function encodePng(image: RawImage, options?: PngEncodeOptions): Uint8Array<ArrayBuffer>;
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/image/png-filter.d.ts
|
|
66
|
-
type PngFilterType = 0 | 1 | 2 | 3 | 4;
|
|
67
|
-
declare function unfilterScanlines(data: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number): Uint8Array<ArrayBuffer>;
|
|
68
|
-
declare function filterScanlines(raw: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number, strategy?: 'none' | 'adaptive'): Uint8Array<ArrayBuffer>;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/image/jpeg-info.d.ts
|
|
71
|
-
interface JpegInfo {
|
|
72
|
-
readonly width: number;
|
|
73
|
-
readonly height: number;
|
|
74
|
-
readonly components: number;
|
|
75
|
-
readonly precision: number;
|
|
76
|
-
readonly progressive: boolean;
|
|
77
|
-
readonly adobeTransform: number | undefined;
|
|
78
|
-
}
|
|
79
|
-
declare function readJpegInfo(bytes: Uint8Array<ArrayBuffer>): JpegInfo;
|
|
80
|
-
//#endregion
|
|
81
|
-
export { ByteReader, ByteWriter, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, concatBytes, crc32, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, readJpegInfo, unfilterScanlines };
|
package/dist/index-DCdK98vS.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
//#region src/bytes/writer.d.ts
|
|
2
|
-
declare class ByteWriter {
|
|
3
|
-
private readonly chunks;
|
|
4
|
-
private byteLength;
|
|
5
|
-
get length(): number;
|
|
6
|
-
writeBytes(bytes: Uint8Array<ArrayBuffer>): void;
|
|
7
|
-
writeByte(byte: number): void;
|
|
8
|
-
writeAscii(text: string): void;
|
|
9
|
-
toBytes(): Uint8Array<ArrayBuffer>;
|
|
10
|
-
}
|
|
11
|
-
declare function concatBytes(chunks: readonly Uint8Array<ArrayBuffer>[]): Uint8Array<ArrayBuffer>;
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/bytes/reader.d.ts
|
|
14
|
-
declare function isAsciiWhitespace(byte: number | undefined): boolean;
|
|
15
|
-
declare class ByteReader {
|
|
16
|
-
private readonly bytes;
|
|
17
|
-
private position;
|
|
18
|
-
constructor(bytes: Uint8Array<ArrayBuffer>);
|
|
19
|
-
get offset(): number;
|
|
20
|
-
get length(): number;
|
|
21
|
-
atEnd(): boolean;
|
|
22
|
-
peek(aheadBy?: number): number | undefined;
|
|
23
|
-
next(): number | undefined;
|
|
24
|
-
mark(): number;
|
|
25
|
-
reset(mark: number): void;
|
|
26
|
-
seek(offset: number): void;
|
|
27
|
-
slice(start: number, end: number): Uint8Array<ArrayBuffer>;
|
|
28
|
-
skipWhitespace(): void;
|
|
29
|
-
matchKeyword(keyword: string): boolean;
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/bytes/crc32.d.ts
|
|
33
|
-
declare function crc32(bytes: Uint8Array<ArrayBuffer>): number;
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/bytes/flate.d.ts
|
|
36
|
-
declare const MAX_INFLATE_OUTPUT_BYTES: number;
|
|
37
|
-
type DeflateLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
38
|
-
declare function deflate(data: Uint8Array<ArrayBuffer>, level?: DeflateLevel): Uint8Array<ArrayBuffer>;
|
|
39
|
-
declare function inflate(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
40
|
-
interface InflateResult {
|
|
41
|
-
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
42
|
-
readonly recovered: boolean;
|
|
43
|
-
}
|
|
44
|
-
declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/image/png-decode.d.ts
|
|
47
|
-
interface RawImage {
|
|
48
|
-
readonly width: number;
|
|
49
|
-
readonly height: number;
|
|
50
|
-
readonly channels: 1 | 3;
|
|
51
|
-
readonly data: Uint8Array<ArrayBuffer>;
|
|
52
|
-
readonly alpha?: Uint8Array<ArrayBuffer>;
|
|
53
|
-
}
|
|
54
|
-
interface PngDecodeOptions {
|
|
55
|
-
readonly onWarning?: (message: string) => void;
|
|
56
|
-
}
|
|
57
|
-
declare function decodePng(bytes: Uint8Array<ArrayBuffer>, options?: PngDecodeOptions): RawImage;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/image/png-encode.d.ts
|
|
60
|
-
interface PngEncodeOptions {
|
|
61
|
-
readonly filter?: 'none' | 'adaptive';
|
|
62
|
-
}
|
|
63
|
-
declare function encodePng(image: RawImage, options?: PngEncodeOptions): Uint8Array<ArrayBuffer>;
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/image/png-filter.d.ts
|
|
66
|
-
type PngFilterType = 0 | 1 | 2 | 3 | 4;
|
|
67
|
-
declare function unfilterScanlines(data: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number): Uint8Array<ArrayBuffer>;
|
|
68
|
-
declare function filterScanlines(raw: Uint8Array<ArrayBuffer>, height: number, bytesPerRow: number, bpp: number, strategy?: 'none' | 'adaptive'): Uint8Array<ArrayBuffer>;
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/image/jpeg-info.d.ts
|
|
71
|
-
interface JpegInfo {
|
|
72
|
-
readonly width: number;
|
|
73
|
-
readonly height: number;
|
|
74
|
-
readonly components: number;
|
|
75
|
-
readonly precision: number;
|
|
76
|
-
readonly progressive: boolean;
|
|
77
|
-
readonly adobeTransform: number | undefined;
|
|
78
|
-
}
|
|
79
|
-
declare function readJpegInfo(bytes: Uint8Array<ArrayBuffer>): JpegInfo;
|
|
80
|
-
//#endregion
|
|
81
|
-
export { ByteReader, ByteWriter, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, concatBytes, crc32, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, readJpegInfo, unfilterScanlines };
|