Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions supabase/functions/edifice-map-generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,30 @@ function crc32(data: Uint8Array): number {
return (c ^ 0xFFFFFFFF) >>> 0;
}

async function zlibDecompress(data: Uint8Array): Promise<Uint8Array> {
async function zlibDecompress(data: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>> {
return streamTransform(new DecompressionStream("deflate"), data);
}

async function zlibCompress(data: Uint8Array): Promise<Uint8Array> {
async function zlibCompress(data: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>> {
return streamTransform(new CompressionStream("deflate"), data);
}

// Two type facts drive these signatures under Deno 2.x / TypeScript 5.7, and neither is
// cosmetic:
// 1. CompressionStream and DecompressionStream declare `writable: WritableStream<BufferSource>`,
// which is wider than Uint8Array — so a `TransformStream<Uint8Array, Uint8Array>`
// parameter asked for something narrower than either class provides.
// 2. Since TS 5.7 typed arrays are generic over their backing buffer: bare `Uint8Array`
// means `Uint8Array<ArrayBufferLike>`, which admits SharedArrayBuffer, while
// `BufferSource` requires `ArrayBufferView<ArrayBuffer>`. So a bare Uint8Array is not
// writable to these streams.
// Hence `Uint8Array<ArrayBuffer>` throughout the PNG codec path: it states that these buffers
// are never shared, which is already true — every one of them comes from `new Uint8Array(n)`
// or a `Response.arrayBuffer()`. A cast would have silenced the checker without saying so.
async function streamTransform(
xform: TransformStream<Uint8Array, Uint8Array>,
data: Uint8Array,
): Promise<Uint8Array> {
xform: TransformStream<BufferSource, Uint8Array>,
data: Uint8Array<ArrayBuffer>,
): Promise<Uint8Array<ArrayBuffer>> {
const writer = xform.writable.getWriter();
const reader = xform.readable.getReader();
const chunks: Uint8Array[] = [];
Expand Down
Loading