forked from galkahana/HummusJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDFRStreamForFile.js
58 lines (47 loc) · 1.25 KB
/
PDFRStreamForFile.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var fs = require('fs');
/*
PDFRStreamForFile is an implementation of a read stream using the supplied file path.
*/
function PDFRStreamForFile(inPath)
{
this.rs = fs.openSync(inPath,'r');
this.path = inPath;
this.rposition = 0;
this.fileSize = fs.statSync(inPath)["size"];
}
PDFRStreamForFile.prototype.read = function(inAmount)
{
var buffer = new Buffer(inAmount*2);
var bytesRead = fs.readSync(this.rs, buffer, 0, inAmount,this.rposition);
var arr = [];
for(var i=0;i<bytesRead;++i)
arr.push(buffer[i]);
this.rposition+=bytesRead;
return arr;
}
PDFRStreamForFile.prototype.notEnded = function()
{
return this.rposition < this.fileSize;
}
PDFRStreamForFile.prototype.setPosition = function(inPosition)
{
this.rposition = inPosition;
}
PDFRStreamForFile.prototype.setPositionFromEnd = function(inPosition)
{
this.rposition = this.fileSize-inPosition;
}
PDFRStreamForFile.prototype.skip = function(inAmount)
{
this.rposition += inAmount;
}
PDFRStreamForFile.prototype.getCurrentPosition = function()
{
return this.rposition;
}
function noop() {}
PDFRStreamForFile.prototype.close = function(inCallback)
{
fs.close(this.rs,inCallback ? inCallback : noop);
};
module.exports = PDFRStreamForFile;