Skip to content

Commit

Permalink
Revert "Attempt to work around Deno zlib regression"
Browse files Browse the repository at this point in the history
This reverts commit e1885e0.

Deno merged a fix:
* denoland/deno#19540 (comment)

Should land in v1.36.2.
  • Loading branch information
danopia committed Aug 14, 2023
1 parent ba44486 commit 17abfb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 41 deletions.
13 changes: 5 additions & 8 deletions lib/spdy-transport/protocol/spdy/zlib-pool.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Buffer } from 'node:buffer';
import { createDeflate,constants,createInflate, Deflate } from 'node:zlib';
import { Inflate } from "https://deno.land/x/[email protected]/zlib/mod.ts";
import { createDeflate,constants,createInflate, Deflate, Inflate } from 'node:zlib';
import { dictionary } from "./dictionary.ts";

export { type Deflate, Inflate, constants };

// TODO(indutny): think about it, why has it always been Z_SYNC_FLUSH here.
// It should be possible to manually flush stuff after the write instead
function _createDeflate (version: 2|3|3.1, compression: boolean) {
const deflate = createDeflate({
// dictionary: Buffer.from(dictionary[version]),
dictionary: Buffer.from(dictionary[version]),
flush: constants.Z_SYNC_FLUSH,
windowBits: 11,
level: compression ? constants.Z_DEFAULT_COMPRESSION : constants.Z_NO_COMPRESSION
Expand All @@ -19,9 +16,9 @@ function _createDeflate (version: 2|3|3.1, compression: boolean) {
}

function _createInflate (version: 2|3|3.1) {
const inflate = new Inflate({
dictionary: dictionary[version],
// flush: constants.Z_SYNC_FLUSH
const inflate = createInflate({
dictionary: Buffer.from(dictionary[version]),
flush: constants.Z_SYNC_FLUSH
})

return inflate
Expand Down
37 changes: 4 additions & 33 deletions lib/spdy-transport/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from "node:events";
import type { Buffer } from "node:buffer";
import { constants, type Deflate, Inflate } from "./protocol/spdy/zlib-pool.ts";
import type { Deflate, Inflate } from "node:zlib";
import type { ClassicCallback } from "./protocol/types.ts";

export class QueueItem {
Expand Down Expand Up @@ -75,23 +75,8 @@ export class LockStream {

this.locked = true

if (this.stream instanceof Inflate) {
// TODO: error handling
const output: Uint8Array[] = []
for (const chunk of chunks) {
output.push(this.stream.push(chunk, constants.Z_SYNC_FLUSH));
}

this.locked = false
if (this.queue.length > 0) { this.queue.shift()!() }
callback(null, output);
return;
}

const stream = this.stream;

const done = (err?: Error | null, chunks?: Uint8Array[]) => {
stream.removeListener('error', done)
this.stream.removeListener('error', done)

this.locked = false
if (this.queue.length > 0) { this.queue.shift()!() }
Expand All @@ -108,7 +93,7 @@ export class LockStream {
this.stream.on('data', onData)

const next = (err?: Error | null) => {
stream.removeListener('data', onData)
this.stream.removeListener('data', onData)
if (err) {
return done(err)
}
Expand Down Expand Up @@ -175,20 +160,6 @@ export class InflateDeflateQueue extends QueuingMutex<Uint8Array[],Uint8Array[]>

async transformOne(chunks: Uint8Array[]): Promise<Uint8Array[]> {

if (this.stream instanceof Inflate) {
// TODO: error handling
const output: Uint8Array[] = []
for (const chunk of chunks) {
output.push(this.stream.push(chunk, constants.Z_SYNC_FLUSH));
}

this.locked = false
if (this.queue.length > 0) { this.queue.shift()!() }
return output;
}

const stream = this.stream;

// Accumulate all output data
const output: Uint8Array[] = []
function onData (chunk: Buffer) {
Expand All @@ -199,7 +170,7 @@ export class InflateDeflateQueue extends QueuingMutex<Uint8Array[],Uint8Array[]>
try {
for (const chunk of chunks) {
await new Promise<void>((ok, fail) => {
stream.write(chunk, err => err ? fail(err) : ok());
this.stream.write(chunk, err => err ? fail(err) : ok());
});
}

Expand Down

0 comments on commit 17abfb0

Please sign in to comment.