pdf.js/src/core/stream.js

357 lines
9.7 KiB
JavaScript
Raw Normal View History

2012-09-01 07:48:21 +09:00
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-var */
2011-10-26 10:18:22 +09:00
import { stringToBytes, unreachable } from "../shared/util.js";
2011-12-09 07:18:43 +09:00
var Stream = (function StreamClosure() {
// eslint-disable-next-line no-shadow
2011-12-09 07:18:43 +09:00
function Stream(arrayBuffer, start, length, dict) {
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
this.bytes =
arrayBuffer instanceof Uint8Array
? arrayBuffer
: new Uint8Array(arrayBuffer);
2011-10-25 08:55:23 +09:00
this.start = start || 0;
this.pos = this.start;
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
this.end = start + length || this.bytes.length;
this.dict = dict;
2011-10-25 08:55:23 +09:00
}
// required methods for a stream. if a particular stream does not
// implement these, an error should be thrown
2011-12-09 07:18:43 +09:00
Stream.prototype = {
2011-10-25 08:55:23 +09:00
get length() {
return this.end - this.start;
},
get isEmpty() {
return this.length === 0;
},
getByte: function Stream_getByte() {
2014-03-23 05:19:08 +09:00
if (this.pos >= this.end) {
2013-07-01 05:45:15 +09:00
return -1;
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
return this.bytes[this.pos++];
},
getUint16: function Stream_getUint16() {
var b0 = this.getByte();
var b1 = this.getByte();
if (b0 === -1 || b1 === -1) {
return -1;
}
return (b0 << 8) + b1;
},
getInt32: function Stream_getInt32() {
var b0 = this.getByte();
var b1 = this.getByte();
var b2 = this.getByte();
var b3 = this.getByte();
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
},
// Returns subarray of original buffer, should only be read.
getBytes(length, forceClamped = false) {
2011-10-25 08:55:23 +09:00
var bytes = this.bytes;
var pos = this.pos;
var strEnd = this.end;
2014-03-23 05:19:08 +09:00
if (!length) {
const subarray = bytes.subarray(pos, strEnd);
// `this.bytes` is always a `Uint8Array` here.
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
var end = pos + length;
2014-03-23 05:19:08 +09:00
if (end > strEnd) {
2011-10-25 08:55:23 +09:00
end = strEnd;
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
this.pos = end;
const subarray = bytes.subarray(pos, end);
// `this.bytes` is always a `Uint8Array` here.
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
2011-10-25 08:55:23 +09:00
},
peekByte: function Stream_peekByte() {
var peekedByte = this.getByte();
if (peekedByte !== -1) {
this.pos--;
}
return peekedByte;
},
peekBytes(length, forceClamped = false) {
var bytes = this.getBytes(length, forceClamped);
this.pos -= bytes.length;
return bytes;
},
getByteRange(begin, end) {
if (begin < 0) {
begin = 0;
}
if (end > this.end) {
end = this.end;
}
return this.bytes.subarray(begin, end);
},
skip: function Stream_skip(n) {
2014-03-23 05:19:08 +09:00
if (!n) {
2011-10-25 08:55:23 +09:00
n = 1;
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
this.pos += n;
},
reset: function Stream_reset() {
2011-10-25 08:55:23 +09:00
this.pos = this.start;
},
moveStart: function Stream_moveStart() {
2011-10-25 08:55:23 +09:00
this.start = this.pos;
},
makeSubStream: function Stream_makeSubStream(start, length, dict) {
2011-10-25 08:55:23 +09:00
return new Stream(this.bytes.buffer, start, length, dict);
},
};
2011-12-09 07:18:43 +09:00
return Stream;
2011-10-25 08:55:23 +09:00
})();
2011-12-09 07:18:43 +09:00
var StringStream = (function StringStreamClosure() {
// eslint-disable-next-line no-shadow
2011-12-09 07:18:43 +09:00
function StringStream(str) {
const bytes = stringToBytes(str);
2011-10-25 08:55:23 +09:00
Stream.call(this, bytes);
}
2011-12-09 07:18:43 +09:00
StringStream.prototype = Stream.prototype;
2011-10-25 08:55:23 +09:00
2011-12-09 07:18:43 +09:00
return StringStream;
2011-10-25 08:55:23 +09:00
})();
// super class for the decoding streams
2011-12-09 07:18:43 +09:00
var DecodeStream = (function DecodeStreamClosure() {
// Lots of DecodeStreams are created whose buffers are never used. For these
// we share a single empty buffer. This is (a) space-efficient and (b) avoids
// having special cases that would be required if we used |null| for an empty
// buffer.
var emptyBuffer = new Uint8Array(0);
// eslint-disable-next-line no-shadow
function DecodeStream(maybeMinBufferLength) {
this._rawMinBufferLength = maybeMinBufferLength || 0;
2011-10-25 08:55:23 +09:00
this.pos = 0;
this.bufferLength = 0;
this.eof = false;
this.buffer = emptyBuffer;
this.minBufferLength = 512;
if (maybeMinBufferLength) {
// Compute the first power of two that is as big as maybeMinBufferLength.
while (this.minBufferLength < maybeMinBufferLength) {
this.minBufferLength *= 2;
}
}
2011-10-25 08:55:23 +09:00
}
2011-12-09 07:18:43 +09:00
DecodeStream.prototype = {
// eslint-disable-next-line getter-return
get length() {
unreachable("Should not access DecodeStream.length");
},
get isEmpty() {
while (!this.eof && this.bufferLength === 0) {
this.readBlock();
}
return this.bufferLength === 0;
},
ensureBuffer: function DecodeStream_ensureBuffer(requested) {
2011-10-25 08:55:23 +09:00
var buffer = this.buffer;
if (requested <= buffer.byteLength) {
return buffer;
}
var size = this.minBufferLength;
while (size < requested) {
size *= 2;
}
2011-10-25 08:55:23 +09:00
var buffer2 = new Uint8Array(size);
buffer2.set(buffer);
2011-10-25 08:55:23 +09:00
return (this.buffer = buffer2);
},
getByte: function DecodeStream_getByte() {
2011-10-25 08:55:23 +09:00
var pos = this.pos;
while (this.bufferLength <= pos) {
2014-03-23 05:19:08 +09:00
if (this.eof) {
2013-07-01 05:45:15 +09:00
return -1;
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
this.readBlock();
}
return this.buffer[this.pos++];
},
getUint16: function DecodeStream_getUint16() {
var b0 = this.getByte();
var b1 = this.getByte();
if (b0 === -1 || b1 === -1) {
return -1;
}
return (b0 << 8) + b1;
},
getInt32: function DecodeStream_getInt32() {
var b0 = this.getByte();
var b1 = this.getByte();
var b2 = this.getByte();
var b3 = this.getByte();
return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
},
getBytes(length, forceClamped = false) {
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
var end,
pos = this.pos;
2011-10-25 08:55:23 +09:00
if (length) {
this.ensureBuffer(pos + length);
end = pos + length;
2014-03-23 05:19:08 +09:00
while (!this.eof && this.bufferLength < end) {
2011-10-25 08:55:23 +09:00
this.readBlock();
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
var bufEnd = this.bufferLength;
2014-03-23 05:19:08 +09:00
if (end > bufEnd) {
2011-10-25 08:55:23 +09:00
end = bufEnd;
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
} else {
2014-03-23 05:19:08 +09:00
while (!this.eof) {
2011-10-25 08:55:23 +09:00
this.readBlock();
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
end = this.bufferLength;
}
this.pos = end;
const subarray = this.buffer.subarray(pos, end);
// `this.buffer` is either a `Uint8Array` or `Uint8ClampedArray` here.
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
return forceClamped && !(subarray instanceof Uint8ClampedArray)
? new Uint8ClampedArray(subarray)
: subarray;
2011-10-25 08:55:23 +09:00
},
peekByte: function DecodeStream_peekByte() {
var peekedByte = this.getByte();
if (peekedByte !== -1) {
this.pos--;
}
return peekedByte;
},
peekBytes(length, forceClamped = false) {
var bytes = this.getBytes(length, forceClamped);
this.pos -= bytes.length;
return bytes;
},
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
if (length === undefined) {
while (!this.eof) {
this.readBlock();
}
} else {
var end = start + length;
while (this.bufferLength <= end && !this.eof) {
this.readBlock();
}
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
return new Stream(this.buffer, start, length, dict);
},
getByteRange(begin, end) {
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
unreachable("Should not call DecodeStream.getByteRange");
},
skip: function DecodeStream_skip(n) {
2014-03-23 05:19:08 +09:00
if (!n) {
2011-10-25 08:55:23 +09:00
n = 1;
2014-03-23 05:19:08 +09:00
}
2011-10-25 08:55:23 +09:00
this.pos += n;
},
reset: function DecodeStream_reset() {
2011-10-25 08:55:23 +09:00
this.pos = 0;
},
getBaseStreams: function DecodeStream_getBaseStreams() {
if (this.str && this.str.getBaseStreams) {
return this.str.getBaseStreams();
}
return [];
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on *Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.* http://eslint.org/docs/rules/comma-dangle http://eslint.org/docs/rules/object-curly-spacing Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead. Please note: This patch was created automatically, using the ESLint --fix command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch. ```diff diff --git a/src/core/evaluator.js b/src/core/evaluator.js index abab9027..dcd3594b 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() { t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, }; t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, }; t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, }; - t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, }; + t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, + variableArgs: false, }; t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, }; t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, }; t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, }; diff --git a/src/core/jbig2.js b/src/core/jbig2.js index 5a17d482..71671541 100644 --- a/src/core/jbig2.js +++ b/src/core/jbig2.js @@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() { { x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, }, { x: -1, y: 0, }], [{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, }, - { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }] + { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, + { x: -1, y: 0, }] ]; var RefinementTemplates = [ { coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }], - reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, - { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }], + reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, + { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, }, + { x: 0, y: 1, }, { x: 1, y: 1, }], }, { - coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }], - reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, }, - { x: 0, y: 1, }, { x: 1, y: 1, }], + coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, + { x: -1, y: 0, }], + reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, + { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }], } ]; ```
2017-06-02 18:16:24 +09:00
},
2011-10-25 08:55:23 +09:00
};
2011-12-09 07:18:43 +09:00
return DecodeStream;
2011-10-25 08:55:23 +09:00
})();
2011-12-09 07:18:43 +09:00
var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
// eslint-disable-next-line no-shadow
2011-12-09 07:18:43 +09:00
function StreamsSequenceStream(streams) {
2011-10-25 08:55:23 +09:00
this.streams = streams;
let maybeLength = 0;
for (let i = 0, ii = streams.length; i < ii; i++) {
const stream = streams[i];
if (stream instanceof DecodeStream) {
maybeLength += stream._rawMinBufferLength;
} else {
maybeLength += stream.length;
}
}
DecodeStream.call(this, maybeLength);
2011-10-25 08:55:23 +09:00
}
2011-12-09 07:18:43 +09:00
StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
2011-10-25 08:55:23 +09:00
var streams = this.streams;
if (streams.length === 0) {
2011-10-25 08:55:23 +09:00
this.eof = true;
return;
}
var stream = streams.shift();
var chunk = stream.getBytes();
var bufferLength = this.bufferLength;
var newLength = bufferLength + chunk.length;
var buffer = this.ensureBuffer(newLength);
buffer.set(chunk, bufferLength);
this.bufferLength = newLength;
};
Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
var baseStreams = [];
for (var i = 0, ii = this.streams.length; i < ii; i++) {
var stream = this.streams[i];
if (stream.getBaseStreams) {
baseStreams.push(...stream.getBaseStreams());
}
}
return baseStreams;
};
2011-12-09 07:18:43 +09:00
return StreamsSequenceStream;
2011-10-25 08:55:23 +09:00
})();
2012-10-23 00:53:15 +09:00
var NullStream = (function NullStreamClosure() {
// eslint-disable-next-line no-shadow
2012-10-23 00:53:15 +09:00
function NullStream() {
Stream.call(this, new Uint8Array(0));
}
NullStream.prototype = Stream.prototype;
return NullStream;
})();
export {
DecodeStream,
NullStream,
Stream,
StreamsSequenceStream,
StringStream,
};