Skip to content

Commit

Permalink
fixup! fixup! fix(ext/web): Prevent (De-)CompressionStream resource l…
Browse files Browse the repository at this point in the history
…eak on stream cancellation
  • Loading branch information
egfx-notifications committed Nov 30, 2023
1 parent 79adfb2 commit 9c096c2
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion cli/tests/unit/streams_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, fail } from "./test_util.ts";
import { assertEquals, assertRejects, fail } from "./test_util.ts";

const {
core,
Expand Down Expand Up @@ -500,3 +500,28 @@ Deno.test(async function decompressionStreamReadableMayBeCancelled() {
new DecompressionStream("deflate-raw").readable.getReader().cancel(),
]);
});

Deno.test(async function decompressionStreamValidGzipDoesNotThrow() {
const cs = new CompressionStream("gzip");
const ds = new DecompressionStream("gzip");
cs.readable.pipeThrough(ds);
const writer = cs.writable.getWriter();
await writer.write(new Uint8Array([1]));
writer.releaseLock();
await cs.writable.close();
let result = new Uint8Array();
for await (const chunk of ds.readable.values()) {
result = new Uint8Array([...result, ...chunk]);
}
assertEquals(result, new Uint8Array([1]));
});

Deno.test(async function decompressionStreamInvalidGzipStillReported() {
await assertRejects(
async () => {
await new DecompressionStream("gzip").writable.close();
},
TypeError,
"corrupt gzip stream does not have a matching checksum",
);
});

0 comments on commit 9c096c2

Please sign in to comment.