-
Notifications
You must be signed in to change notification settings - Fork 170
/
PDFWStreamForFile.js
51 lines (44 loc) · 971 Bytes
/
PDFWStreamForFile.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
var fs = require('fs');
/*
PDFWStreamForFile is an implementation of a write stream using the supplied file path.
*/
function PDFWStreamForFile(inPath)
{
this.ws = fs.createWriteStream(inPath);
this.position = 0;
this.path = inPath;
}
PDFWStreamForFile.prototype.write = function(inBytesArray)
{
if(inBytesArray.length > 0)
{
this.ws.write(Buffer.from(inBytesArray));
this.position+=inBytesArray.length;
return inBytesArray.length;
}
else
return 0;
};
PDFWStreamForFile.prototype.getCurrentPosition = function()
{
return this.position;
};
PDFWStreamForFile.prototype.close = function(inCallback)
{
if(this.ws)
{
var self = this;
this.ws.end(function()
{
self.ws = null;
if(inCallback)
inCallback();
})
}
else
{
if(inCallback)
inCallback();
}
};
module.exports = PDFWStreamForFile;