-
Notifications
You must be signed in to change notification settings - Fork 170
/
PDFRStreamForBuffer.js
41 lines (31 loc) · 1.04 KB
/
PDFRStreamForBuffer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
PDFRStreamForBuffer is an implementation of a read stream using a supplied array
@author Luciano Júnior
*/
function PDFRStreamForBuffer(buffer){
this.innerArray = Array.prototype.slice.call(buffer, 0);
this.rposition = 0;
this.fileSize = this.innerArray.length;
}
PDFRStreamForBuffer.prototype.read = function(inAmount){
var amountToRead = inAmount;
var arr = this.innerArray.slice(this.rposition,this.rposition+amountToRead);
this.rposition += amountToRead;
return arr;
}
PDFRStreamForBuffer.prototype.notEnded = function(){
return this.rposition < this.fileSize;
}
PDFRStreamForBuffer.prototype.setPosition = function(inPosition){
this.rposition = inPosition;
}
PDFRStreamForBuffer.prototype.setPositionFromEnd = function(inPosition){
this.rposition = this.fileSize-inPosition;
}
PDFRStreamForBuffer.prototype.skip = function(inAmount){
this.rposition += inAmount;
}
PDFRStreamForBuffer.prototype.getCurrentPosition = function(){
return this.rposition;
}
module.exports = PDFRStreamForBuffer;