forked from aadsm/JavaScript-ID3-Reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryNodeFile.js
More file actions
107 lines (95 loc) · 2.62 KB
/
Copy pathbinaryNodeFile.js
File metadata and controls
107 lines (95 loc) · 2.62 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @constructor
*/
function BinaryNodeFile(file, iDataOffset, iDataLength) {
this.getRawData = function() {
return buffer;
};
this.getByteAt = function(iOffset) {
return buffer.readUInt8(iOffset);
};
// @aadsm
this.getBytesAt = function(iOffset, iLength) {
var result=new Buffer(iLength);
buffer.copy(result, 0, iOffset, iLength);
return result;
};
this.getLength = function() {
return buffer.length;
};
// @aadsm
this.isBitSetAt = function(iOffset, iBit) {
var iByte = this.getByteAt(iOffset);
return (iByte & (1 << iBit)) != 0;
};
this.getSByteAt = function(iOffset) {
return buffer.readInt8(iOffset);
};
this.getShortAt = function(iOffset, bBigEndian) {
if(bBigEndian)
return buffer.readUInt16BE(iOffset);
else
return buffer.readUInt16LE(iOffset);
};
this.getSShortAt = function(iOffset, bBigEndian) {
if(bBigEndian)
return buffer.readInt16BE(iOffset);
else
return buffer.readInt16LE(iOffset);
};
this.getLongAt = function(iOffset, bBigEndian) {
if(bBigEndian)
return buffer.readUInt32BE(iOffset);
else
return buffer.readUInt32LE(iOffset);
};
this.getSLongAt = function(iOffset, bBigEndian) {
if(bBigEndian)
return buffer.readInt16BE(iOffset);
else
return buffer.readInt16LE(iOffset);
};
// @aadsm
this.getInteger24At = function(iOffset, bBigEndian) {
var iByte1 = this.getByteAt(iOffset),
iByte2 = this.getByteAt(iOffset + 1),
iByte3 = this.getByteAt(iOffset + 2);
var iInteger = bBigEndian ?
((((iByte1 << 8) + iByte2) << 8) + iByte3)
: ((((iByte3 << 8) + iByte2) << 8) + iByte1);
if (iInteger < 0) iInteger += 16777216;
return iInteger;
};
this.getStringAt = function(iOffset, iLength) {
return buffer.toString(iOffset, iLength);
};
// @aadsm
this.getStringWithCharsetAt = function(iOffset, iLength, iCharset) {
switch( iCharset.toLowerCase() ) {
case 'utf-16':
case 'utf-16le':
case 'utf-16be':
return buffer.toString('utf16le', iOffset, iLength);
case 'utf-8':
return buffer.toString('utf8', iOffset, iLength);
default:
return StringUtils.readNullTerminatedString(bytes);
}
};
this.getCharAt = function(iOffset) {
return this.getString(iOffset, 1);
};
this.toBase64 = function() {
return buffer.toString('base64');
};
this.fromBase64 = function(strBase64) {
buffer=new Buffer(strBase64, 'base64');
};
this.loadRange = function(range, callback) {
buffer=new Buffer(range[1]-range[0]);
fs.read(file, buffer, 0, range[1]-range[0], range[0], function(err, bytesRead, buf){
buffer=buf;
callback();
});
};
}