Skip to content

Commit 7a6b741

Browse files
committed
Refactor: use standard web streams (#1)
1 parent 1e6b492 commit 7a6b741

File tree

105 files changed

+5428
-6666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+5428
-6666
lines changed

.c8rc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"all": true,
3+
"exclude": ["*.js", "*.d.ts", "**/*.test.ts", "types/"],
4+
"reporter": ["text", "lcovonly"]
5+
}

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- uses: actions/setup-node@v4
1515
with:
16-
node-version: "22.x"
16+
node-version-file: ".node-version"
1717
cache: "npm"
1818
registry-url: "https://registry.npmjs.org"
1919

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- uses: actions/setup-node@v4
2626
with:
27-
node-version: "22.x"
27+
node-version-file: ".node-version"
2828
cache: "npm"
2929
registry-url: "https://registry.npmjs.org"
3030

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24.0.1

.vscode/settings.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
},
77
"eslint.useFlatConfig": true,
88
"typescript.tsdk": "node_modules/typescript/lib",
9-
"cSpell.words": ["decompressors"],
10-
"code-coverage-lcov.path.searchPath": "coverage/lcov.info"
9+
"cSpell.words": ["decompressors", "eocdl", "eocdr"],
10+
"code-coverage-lcov.path.searchPath": "coverage/lcov.info",
11+
"nodejs-testing.extensions": [
12+
{
13+
"extensions": ["ts"],
14+
"parameters": []
15+
}
16+
]
1117
}

CHANGELOG.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,31 @@
22

33
## [0.1.7](https://github.com/gordonmleigh/zip24/compare/v0.1.6...v0.1.7) (2025-03-25)
44

5-
65
### Fix
76

8-
* DataView is now generic ([a030c33](https://github.com/gordonmleigh/zip24/commit/a030c33d5d94c274421f4b1868d35acdf09ebecb))
7+
- DataView is now generic ([a030c33](https://github.com/gordonmleigh/zip24/commit/a030c33d5d94c274421f4b1868d35acdf09ebecb))
98

109
## [0.1.6](https://github.com/gordonmleigh/zip24/compare/v0.1.4...v0.1.6) (2024-10-05)
1110

12-
1311
### Chore
1412

15-
* add helpful error in core compress ([574b59d](https://github.com/gordonmleigh/zip24/commit/574b59d77834cdf4e93f88585914a0e66090179d))
16-
* improve tests for writers ([b2f21d8](https://github.com/gordonmleigh/zip24/commit/b2f21d88b42e66a43c0979e1fe5ac33e9c2c7407))
17-
* make DoubleEndedBuffer unconstrained ([d0a0c2d](https://github.com/gordonmleigh/zip24/commit/d0a0c2d23077e5aadeb789f62b405025790488c1))
18-
* version bump ([4556969](https://github.com/gordonmleigh/zip24/commit/4556969b31c08617a1772ad94d028b0912a6714e))
13+
- add helpful error in core compress ([574b59d](https://github.com/gordonmleigh/zip24/commit/574b59d77834cdf4e93f88585914a0e66090179d))
14+
- improve tests for writers ([b2f21d8](https://github.com/gordonmleigh/zip24/commit/b2f21d88b42e66a43c0979e1fe5ac33e9c2c7407))
15+
- make DoubleEndedBuffer unconstrained ([d0a0c2d](https://github.com/gordonmleigh/zip24/commit/d0a0c2d23077e5aadeb789f62b405025790488c1))
16+
- version bump ([4556969](https://github.com/gordonmleigh/zip24/commit/4556969b31c08617a1772ad94d028b0912a6714e))
1917

2018
## [0.1.4](https://github.com/gordonmleigh/zip24/compare/v0.1.3...v0.1.4) (2024-10-04)
2119

22-
2320
### Build
2421

25-
* publish provenance attestations ([18c38c0](https://github.com/gordonmleigh/zip24/commit/18c38c078ed2ae5abe4a59d0352e1dd69192b1d3))
26-
* publish to npm automatically ([3e1949c](https://github.com/gordonmleigh/zip24/commit/3e1949cf2e1cc978c97f97ce1cfe2472ba12e217))
22+
- publish provenance attestations ([18c38c0](https://github.com/gordonmleigh/zip24/commit/18c38c078ed2ae5abe4a59d0352e1dd69192b1d3))
23+
- publish to npm automatically ([3e1949c](https://github.com/gordonmleigh/zip24/commit/3e1949cf2e1cc978c97f97ce1cfe2472ba12e217))
2724

2825
## [0.1.3](https://github.com/gordonmleigh/zip24/compare/v0.1.0...v0.1.3) (2024-10-04)
2926

30-
3127
### Build
3228

33-
* add build script ([4e9da64](https://github.com/gordonmleigh/zip24/commit/4e9da64a430f7eebd566246b41f1aaa019baa196))
34-
* add GitHub Actions workflow ([c5943aa](https://github.com/gordonmleigh/zip24/commit/c5943aadfc82a3b19dd270bdaccc65ba68a71613))
35-
* add release-it ([028f241](https://github.com/gordonmleigh/zip24/commit/028f241c0fb8abde53ed82667cc37abe236a654e))
36-
* upgrade linting ([03bd772](https://github.com/gordonmleigh/zip24/commit/03bd772bc6b76b58cd00be67da4849fe0892cd87))
29+
- add build script ([4e9da64](https://github.com/gordonmleigh/zip24/commit/4e9da64a430f7eebd566246b41f1aaa019baa196))
30+
- add GitHub Actions workflow ([c5943aa](https://github.com/gordonmleigh/zip24/commit/c5943aadfc82a3b19dd270bdaccc65ba68a71613))
31+
- add release-it ([028f241](https://github.com/gordonmleigh/zip24/commit/028f241c0fb8abde53ed82667cc37abe236a654e))
32+
- upgrade linting ([03bd772](https://github.com/gordonmleigh/zip24/commit/03bd772bc6b76b58cd00be67da4849fe0892cd87))

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ Nope! Reading a zip forwards from start to finish is something that the zip form
8282

8383
## Writing Zips
8484

85+
### With `ZipWriter.open()`
86+
87+
You can use `ZipWriter.open()` on Node.js to write directly to a file:
88+
8589
```ts
8690
import { ZipWriter } from "zip24/writer";
8791

@@ -106,9 +110,28 @@ await writer.addFile(
106110
"this will be stored as-is",
107111
);
108112

109-
await writer.finalize("Gordon is cool");
113+
await writer.close();
110114
```
111115

116+
### With `destination` option
117+
118+
You can also output to any writer you'd like. On Node, [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable) is also supported as a destination. Note that the destination must be an instance of `Writable`, not just "Writable-like".
119+
120+
```ts
121+
import { ZipWriter } from "zip24/writer";
122+
123+
const destination = createWritableStreamSomehow();
124+
const writer = new ZipWriter({ destination });
125+
126+
// etc
127+
128+
await writer.close();
129+
```
130+
131+
### With streams
132+
133+
`ZipWriter` is also a [TransformStream](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream), so you can pipe `ZipEntry`/`ZipEntryInfo` instances in and pipe the output to a stream of your choice.
134+
112135
## About this library
113136

114137
### Why `zip24`?

docs/records.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ This record has an optional signature value of `0x08074b50` which precedes the o
9797
| 32 | total entries on all disks | 8 |
9898
| 40 | size of the central directory | 8 |
9999
| 48 | central directory offset | 8 |
100-
| 56 | (end) | |
100+
| 56 | extensible data sector | ... |
101+
| ... | (56 + record size - 12) | |
101102

102103
## Zip64 End of Central Directory Locator (4.3.15)
103104

eslint.config.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,53 @@
1-
import config from "@propulsionworks/eslint-config";
1+
import propulsionworks, { config } from "@propulsionworks/eslint-config";
22

3-
export default [
4-
config.configs["base"],
5-
config.configs["ts"],
3+
export default config(
64
{
5+
ignores: ["node_modules/", "lib/", "eslint.config.js"],
6+
},
7+
{
8+
files: ["**/*.js", "**/*.ts"],
9+
extends: [propulsionworks.configs.js],
10+
},
11+
{
12+
files: ["**/*.ts"],
13+
extends: [propulsionworks.configs.ts],
714
rules: {
8-
//"unicorn/no-unused-properties": "warn",
9-
"unicorn/number-literal-case": "off", // fights with prettier
10-
"unicorn/numeric-separators-style": "off", // annoying
15+
// we can turn this off due to the other rules that stop us abusing `any`
16+
"@typescript-eslint/no-explicit-any": "off",
17+
"@typescript-eslint/no-unused-vars": [
18+
"error",
19+
{ ignoreRestSiblings: true },
20+
],
21+
"@typescript-eslint/unified-signatures": [
22+
"error",
23+
{
24+
ignoreDifferentlyNamedParameters: true,
25+
ignoreOverloadsWithDifferentJSDoc: true,
26+
},
27+
],
28+
"n/no-unsupported-features/node-builtins": "off",
1129
},
1230
},
1331
{
14-
files: ["src/**/*.test.*"],
32+
files: ["**/*.test.ts"],
33+
extends: [propulsionworks.configs["ts-relaxed-any"]],
1534

1635
rules: {
17-
"@typescript-eslint/no-floating-promises": "off", // `describe` and `it` return promises
36+
// `describe` and `it` return promises
37+
"@typescript-eslint/no-floating-promises": [
38+
"warn",
39+
{
40+
allowForKnownSafeCalls: [
41+
{ from: "package", name: ["describe", "it"], package: "node:test" },
42+
],
43+
},
44+
],
45+
1846
"@typescript-eslint/no-non-null-asserted-optional-chain": "off", // easier for testing
1947
"@typescript-eslint/no-non-null-assertion": "off", // easier for testing
20-
"n/no-unsupported-features/node-builtins": "off", // so we can use node:test
48+
"@typescript-eslint/no-unused-vars": "off", // easier for testing
49+
"@typescript-eslint/require-await": "off", // easier for testing
2150
"unicorn/no-abusive-eslint-disable": "off",
2251
},
2352
},
24-
];
53+
);
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import assert from "node:assert";
2-
import { buffer } from "node:stream/consumers";
2+
import { buffer, text } from "node:stream/consumers";
33
import { describe, it, mock } from "node:test";
4-
import { CompressionMethod } from "../core/compression-core.js";
5-
import { ZipPlatform, ZipVersion } from "../core/constants.js";
6-
import { UnixFileAttributes } from "../core/file-attributes.js";
7-
import { ZipEntry } from "../core/zip-entry.js";
84
import {
95
EmptyZip32,
106
Zip32WithThreeEntries,
117
generateZip,
12-
} from "../test-util/fixtures.js";
13-
import { ZipBufferReader } from "./buffer.js";
8+
} from "../test-util/fixtures.ts";
9+
import { ZipBufferReader } from "./buffer.ts";
10+
import { ZipEntry, ZipEntryReader } from "./entry.ts";
11+
import { CompressionMethod, ZipPlatform, ZipVersion } from "./raw/constants.ts";
12+
import { UnixFileAttributes } from "./raw/file-attributes.ts";
1413

1514
describe("web/buffer", () => {
1615
describe("ZipBufferReader", () => {
@@ -44,7 +43,7 @@ describe("web/buffer", () => {
4443
it("iterates all the files", async () => {
4544
const reader = new ZipBufferReader(Zip32WithThreeEntries);
4645

47-
const files: ZipEntry[] = [];
46+
const files: ZipEntryReader[] = [];
4847
for (const file of reader.filesSync()) {
4948
files.push(file);
5049
}
@@ -80,7 +79,7 @@ describe("web/buffer", () => {
8079
assert.strictEqual(file0.isDirectory, false);
8180
assert.strictEqual(file0.isFile, true);
8281

83-
assert.strictEqual(await file0.toText(), "this is the file 1 content");
82+
assert.strictEqual(await text(file0), "this is the file 1 content");
8483

8584
//// FILE 1
8685
const file1 = files[1];
@@ -111,10 +110,7 @@ describe("web/buffer", () => {
111110
assert.strictEqual(file1.isDirectory, false);
112111
assert.strictEqual(file1.isFile, true);
113112

114-
assert.strictEqual(
115-
await file1.toText(),
116-
"file 2 content goes right here",
117-
);
113+
assert.strictEqual(await text(file1), "file 2 content goes right here");
118114

119115
//// FILE 2
120116
const file2 = files[2];
@@ -144,7 +140,7 @@ describe("web/buffer", () => {
144140
assert.strictEqual(file2.isDirectory, true);
145141
assert.strictEqual(file2.isFile, false);
146142

147-
assert.strictEqual(await file2.toText(), "");
143+
assert.strictEqual(await text(file2), "");
148144
});
149145
});
150146

0 commit comments

Comments
 (0)