Skip to content

Commit

Permalink
fix(zlib): Default flush options to Z_SYNC_FLUSH
Browse files Browse the repository at this point in the history
This avoids errors from partial or interrupted streams including an empty stream (eg: HEAD)

fixes #72
  • Loading branch information
colinbendell authored and grantila committed Mar 22, 2020
1 parent 32106bf commit 91e111a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
import { pipeline } from "stream";

import {
constants as zlibConstants,
createBrotliDecompress,
createGunzip,
createInflate,
ZlibOptions,
} from "zlib";

const {
Expand Down Expand Up @@ -276,11 +278,16 @@ function handleEncoding(
// TODO: Add error handling
};

const zlibOpts: ZlibOptions = {
flush: zlibConstants.Z_SYNC_FLUSH,
finishFlush: zlibConstants.Z_SYNC_FLUSH,
};

const decoders: { [ name: string ]: DecodeFunction; } = {
deflate: ( stream: NodeJS.ReadableStream ) =>
pipeline( stream, createInflate( ), handleStreamResult ),
gzip: ( stream: NodeJS.ReadableStream ) =>
pipeline( stream, createGunzip( ), handleStreamResult ),
pipeline( stream, createGunzip( zlibOpts ), handleStreamResult ),
};

if ( hasBuiltinBrotli( ) )
Expand Down

0 comments on commit 91e111a

Please sign in to comment.