mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #3374 from yurydelendik/ei-search
Improves search of EI (end of inlined image)
This commit is contained in:
commit
b22bc2daa5
4 changed files with 30 additions and 1 deletions
|
@ -154,13 +154,22 @@ var Parser = (function ParserClosure() {
|
|||
var startPos = stream.pos;
|
||||
|
||||
// searching for the /EI\s/
|
||||
var state = 0, ch;
|
||||
var state = 0, ch, i, ii;
|
||||
while (state != 4 &&
|
||||
(ch = stream.getByte()) !== null && ch !== undefined) {
|
||||
switch (ch) {
|
||||
case 0x20:
|
||||
case 0x0D:
|
||||
case 0x0A:
|
||||
// let's check next five bytes to be ASCII... just be sure
|
||||
var followingBytes = stream.peekBytes(5);
|
||||
for (i = 0, ii = followingBytes.length; i < ii; i++) {
|
||||
ch = followingBytes[i];
|
||||
if (ch !== 0x0A && ch != 0x0D && (ch < 0x20 || ch > 0x7F)) {
|
||||
state = 0;
|
||||
break; // some binary stuff found, resetting the state
|
||||
}
|
||||
}
|
||||
state = state === 3 ? 4 : 0;
|
||||
break;
|
||||
case 0x45:
|
||||
|
|
|
@ -57,6 +57,11 @@ var Stream = (function StreamClosure() {
|
|||
this.pos = end;
|
||||
return bytes.subarray(pos, end);
|
||||
},
|
||||
peekBytes: function Stream_peekBytes(length) {
|
||||
var bytes = this.getBytes(length);
|
||||
this.pos -= bytes.length;
|
||||
return bytes;
|
||||
},
|
||||
lookChar: function Stream_lookChar() {
|
||||
if (this.pos >= this.end)
|
||||
return null;
|
||||
|
@ -161,6 +166,11 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||
this.pos = end;
|
||||
return this.buffer.subarray(pos, end);
|
||||
},
|
||||
peekBytes: function DecodeStream_peekBytes(length) {
|
||||
var bytes = this.getBytes(length);
|
||||
this.pos -= bytes.length;
|
||||
return bytes;
|
||||
},
|
||||
lookChar: function DecodeStream_lookChar() {
|
||||
var pos = this.pos;
|
||||
while (this.bufferLength <= pos) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue