mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58: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
|
@ -598,20 +598,16 @@ class PDFDocument {
|
|||
idArray[0] !== EMPTY_FINGERPRINT) {
|
||||
hash = stringToBytes(idArray[0]);
|
||||
} else {
|
||||
if (this.stream.ensureRange) {
|
||||
this.stream.ensureRange(0,
|
||||
Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
|
||||
}
|
||||
hash = calculateMD5(this.stream.bytes.subarray(0,
|
||||
FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
|
||||
hash = calculateMD5(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES),
|
||||
0, FINGERPRINT_FIRST_BYTES);
|
||||
}
|
||||
|
||||
let fingerprint = '';
|
||||
const fingerprintBuf = [];
|
||||
for (let i = 0, ii = hash.length; i < ii; i++) {
|
||||
const hex = hash[i].toString(16);
|
||||
fingerprint += (hex.length === 1 ? '0' + hex : hex);
|
||||
fingerprintBuf.push(hex.padStart(2, '0'));
|
||||
}
|
||||
return shadow(this, 'fingerprint', fingerprint);
|
||||
return shadow(this, 'fingerprint', fingerprintBuf.join(''));
|
||||
}
|
||||
|
||||
_getLinearizationPage(pageIndex) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue