Tweak the writeStream
implementation slightly
- Do the /Filter and /DecodeParms lookup in parallel, since that ought to be a *tiny* bit more efficient. - Avoid code-duplication when `CompressionStream` isn't supported, since we already have a fallback code-path at the end of the function.
This commit is contained in:
parent
73d650af3e
commit
5cfe792349
@ -51,16 +51,10 @@ async function writeStream(stream, buffer, transform) {
|
|||||||
}
|
}
|
||||||
const { dict } = stream;
|
const { dict } = stream;
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
const [filter, params] = await Promise.all([
|
||||||
if (typeof CompressionStream === "undefined") {
|
dict.getAsync("Filter"),
|
||||||
dict.set("Length", string.length);
|
dict.getAsync("DecodeParms"),
|
||||||
await writeDict(dict, buffer, transform);
|
]);
|
||||||
buffer.push(" stream\n", string, "\nendstream");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filter = await dict.getAsync("Filter");
|
|
||||||
const params = await dict.getAsync("DecodeParms");
|
|
||||||
|
|
||||||
const filterZero = Array.isArray(filter)
|
const filterZero = Array.isArray(filter)
|
||||||
? await dict.xref.fetchIfRefAsync(filter[0])
|
? await dict.xref.fetchIfRefAsync(filter[0])
|
||||||
@ -71,7 +65,11 @@ async function writeStream(stream, buffer, transform) {
|
|||||||
// The number 256 is arbitrary, but it should be reasonable.
|
// The number 256 is arbitrary, but it should be reasonable.
|
||||||
const MIN_LENGTH_FOR_COMPRESSING = 256;
|
const MIN_LENGTH_FOR_COMPRESSING = 256;
|
||||||
|
|
||||||
if (string.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode) {
|
if (
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
typeof CompressionStream !== "undefined" &&
|
||||||
|
(string.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode)
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const byteArray = stringToBytes(string);
|
const byteArray = stringToBytes(string);
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
|
Loading…
x
Reference in New Issue
Block a user