Skip to content

Commit

Permalink
finished bytewiser tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrettmeyer committed Sep 2, 2014
1 parent 386081c commit 1c0e4cc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bytewiser/04_line_splitter.js
@@ -0,0 +1,16 @@
var fs = require('fs');
var path = process.argv[2];
var startIndex = 0;
fs.readFile(path, function (err, data) {
if (err) {
throw err;
}
for (var i = 0, len = data.length; i < len; i += 1) {
if (data[i] === 0x0a) { // 0x0a = '\n'
var bufferLength = i - startIndex;
console.log(data.slice(startIndex, i));
startIndex = i + 1;
}
}
console.log(data.slice(startIndex))
})
8 changes: 8 additions & 0 deletions bytewiser/05_concat.js
@@ -0,0 +1,8 @@
var buffers = [];
process.stdin.on("data", function (chunk) {
buffers.push(chunk);
});
process.stdin.on("end", function () {
var buffer = Buffer.concat(buffers);
console.log(buffer);
})
5 changes: 5 additions & 0 deletions bytewiser/06_typed_arrays.js
@@ -0,0 +1,5 @@
process.stdin.on("data", function (data) {
var a = new Uint8Array(data);
var j = JSON.stringify(a);
console.log(j);
});
4 changes: 4 additions & 0 deletions bytewiser/07_array_buffers.js
@@ -0,0 +1,4 @@
var char = process.argv[2];
var array32 = new Uint32Array([char]);
var array16 = new Uint16Array(array32.buffer);
console.log(JSON.stringify(array16));

0 comments on commit 1c0e4cc

Please sign in to comment.