mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-05-31 07:11:00 +02:00
Merge pull request #21198 from Snuffleupagus/DecryptStream-nextChunk
Simplify the `nextChunk` handling in the `DecryptStream` class
This commit is contained in:
commit
b71be8a501
@ -18,30 +18,24 @@ import { DecodeStream } from "./decode_stream.js";
|
||||
const chunkSize = 512;
|
||||
|
||||
class DecryptStream extends DecodeStream {
|
||||
#nextChunk = null;
|
||||
|
||||
constructor(str, maybeLength, decrypt) {
|
||||
super(maybeLength);
|
||||
|
||||
this.stream = str;
|
||||
this.dict = str.dict;
|
||||
this.decrypt = decrypt;
|
||||
this.nextChunk = null;
|
||||
this.initialized = false;
|
||||
}
|
||||
|
||||
readBlock() {
|
||||
let chunk;
|
||||
if (this.initialized) {
|
||||
chunk = this.nextChunk;
|
||||
} else {
|
||||
chunk = this.stream.getBytes(chunkSize);
|
||||
this.initialized = true;
|
||||
}
|
||||
let chunk = this.#nextChunk ?? this.stream.getBytes(chunkSize);
|
||||
if (!chunk?.length) {
|
||||
this.eof = true;
|
||||
return;
|
||||
}
|
||||
this.nextChunk = this.stream.getBytes(chunkSize);
|
||||
const hasMoreData = this.nextChunk?.length > 0;
|
||||
this.#nextChunk = this.stream.getBytes(chunkSize);
|
||||
const hasMoreData = this.#nextChunk?.length > 0;
|
||||
|
||||
const decrypt = this.decrypt;
|
||||
chunk = decrypt(chunk, !hasMoreData);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user