Qualify kind of stream

This commit is contained in:
Cadence Ember
2025-02-16 17:44:17 +13:00
parent 0d0ca98e13
commit a5fd30d535
11 changed files with 26 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
// @ts-check
const assert = require("assert")
const fs = require("fs")
const {join} = require("path")
const h3 = require("h3")
@@ -38,8 +39,8 @@ function compressResponse(event, response) {
if (!getRequestHeader(event, "accept-encoding")?.includes("gzip")) return
/* c8 ignore next */
if (typeof response.body !== "string") return
/** @type {ReadableStream} */ // @ts-ignore
const stream = new Response(response.body).body
assert(stream)
setResponseHeader(event, "content-encoding", "gzip")
response.body = stream.pipeThrough(new CompressionStream("gzip"))
}

View File

@@ -1,6 +1,6 @@
// @ts-check
const {ReadableStream} = require("stream/web")
const streamWeb = require("stream/web")
const {test} = require("supertape")
const {router} = require("../../test/web")
const assert = require("assert").strict
@@ -30,7 +30,7 @@ test("web server: compresses static resources", async t => {
"accept-encoding": "gzip"
}
})
assert(content instanceof ReadableStream)
assert(content instanceof streamWeb.ReadableStream)
const firstChunk = await content.getReader().read()
t.ok(firstChunk.value instanceof Uint8Array, "can get data")
t.deepEqual(firstChunk.value.slice(0, 3), Uint8Array.from([31, 139, 8]), "has compressed gzip header")