UNPKG

1.02 kBJavaScriptView Raw
1var fs = require('fs');
2
3/*
4 PDFWStreamForFile is an implementation of a write stream using the supplied file path.
5*/
6
7function PDFWStreamForFile(inPath)
8{
9 this.ws = fs.createWriteStream(inPath);
10 this.position = 0;
11 this.path = inPath;
12}
13
14PDFWStreamForFile.prototype.write = function(inBytesArray)
15{
16 if(inBytesArray.length > 0)
17 {
18 this.ws.write(new Buffer(inBytesArray));
19 this.position+=inBytesArray.length;
20 return inBytesArray.length;
21 }
22 else
23 return 0;
24};
25
26PDFWStreamForFile.prototype.getCurrentPosition = function()
27{
28 return this.position;
29};
30
31PDFWStreamForFile.prototype.close = function(inCallback)
32{
33 if(this.ws)
34 {
35 var self = this;
36
37 this.ws.end(function()
38 {
39 self.ws = null;
40 if(inCallback)
41 inCallback();
42 })
43 }
44 else
45 {
46 if(inCallback)
47 inCallback();
48 }
49};
50
51module.exports = PDFWStreamForFile;
\No newline at end of file