forked from archiverjs/node-compress-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (59 loc) · 1.73 KB
/
Copy pathindex.js
File metadata and controls
87 lines (59 loc) · 1.73 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var crypto = require('crypto');
var fs = require('fs');
var inherits = require('util').inherits;
var Stream = require('stream').Stream;
var Readable = require('readable-stream').Readable;
var Writable = require('readable-stream').Writable;
function binaryBuffer(n) {
var buffer = Buffer.alloc(n);
for (var i = 0; i < n; i++) {
buffer.writeUInt8(i&255, i);
}
return buffer;
}
module.exports.binaryBuffer = binaryBuffer;
function BinaryStream(size, options) {
Readable.call(this, options);
var buf = Buffer.alloc(size);
for (var i = 0; i < size; i++) {
buf.writeUInt8(i&255, i);
}
this.push(buf);
this.push(null);
}
inherits(BinaryStream, Readable);
BinaryStream.prototype._read = function(size) {};
module.exports.BinaryStream = BinaryStream;
function DeadEndStream(options) {
Writable.call(this, options);
}
inherits(DeadEndStream, Writable);
DeadEndStream.prototype._write = function(chuck, encoding, callback) {
callback();
};
module.exports.DeadEndStream = DeadEndStream;
function fileBuffer(filepath) {
return fs.readFileSync(filepath);
}
module.exports.fileBuffer = fileBuffer;
function UnBufferedStream() {
this.readable = true;
}
inherits(UnBufferedStream, Stream);
module.exports.UnBufferedStream = UnBufferedStream;
function WriteHashStream(path, options) {
fs.WriteStream.call(this, path, options);
this.hash = crypto.createHash('sha1');
this.digest = null;
this.on('close', function() {
this.digest = this.hash.digest('hex');
});
}
inherits(WriteHashStream, fs.WriteStream);
WriteHashStream.prototype.write = function(chunk) {
if (chunk) {
this.hash.update(chunk);
}
return fs.WriteStream.prototype.write.call(this, chunk);
};
module.exports.WriteHashStream = WriteHashStream;