Reputation: 846
var file = randomAccessFile('gen.mp3')
file.read(0, 5, function(err, buffer) {
console.log(buffer)
for (const value of buffer.values()) {
console.log(value);
}
file.close(function() {
console.log('file is closed')
})
})
The first output is:
<Buffer 49 44 33 03 00>
and the second:
73
68
51
3
0
I need an array, or some other data structure, where I can access the values of the first output individually. How would I do that? Why does the second output convert the hexadecimal to decimal?
Upvotes: 0
Views: 31
Reputation: 13532
You can just access the buffer with [index]
. https://nodejs.org/api/buffer.html#buffer_buf_index
You can print the values in hex if you want as well.
var file = randomAccessFile('gen.mp3')
file.read(0, 5, function(err, buffer) {
console.log(buffer)
console.log(buffer[0]); // prints decimal
console.log(buffer[0].toString(16)); //prints hexadecimal
file.close(function() {
console.log('file is closed')
})
})
Upvotes: 1