mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Simplify the PDFDocument.fingerprint
method slightly
The way that this method handles documents without an `ID` entry in the Trailer dictionary feels overly complicated to me. Hence this patch adds `getByteRange` methods to the various Stream implementations[1], and utilize that rather than manually calling `ensureRange` when computing a fallback `fingerprint`. --- [1] Note that `PDFDocument` is only ever initialized with either a `Stream` or a `ChunkedStream`, hence why the `DecodeStream.getByteRange` method isn't implemented.
This commit is contained in:
parent
c7de6dbe41
commit
bea15b6ce5
3 changed files with 30 additions and 10 deletions
|
@ -19,7 +19,9 @@
|
|||
* license.
|
||||
*/
|
||||
|
||||
import { FormatError, isSpace, stringToBytes } from '../shared/util';
|
||||
import {
|
||||
FormatError, isSpace, stringToBytes, unreachable
|
||||
} from '../shared/util';
|
||||
import { isDict } from './primitives';
|
||||
|
||||
var Stream = (function StreamClosure() {
|
||||
|
@ -92,6 +94,17 @@ var Stream = (function StreamClosure() {
|
|||
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) {
|
||||
if (!n) {
|
||||
n = 1;
|
||||
|
@ -236,6 +249,11 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||
}
|
||||
return new Stream(this.buffer, start, length, dict);
|
||||
},
|
||||
|
||||
getByteRange(begin, end) {
|
||||
unreachable('Should not call DecodeStream.getByteRange');
|
||||
},
|
||||
|
||||
skip: function DecodeStream_skip(n) {
|
||||
if (!n) {
|
||||
n = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue