Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
386081c
commit 1c0e4cc
Showing
4 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
process.stdin.on("data", function (data) { | ||
var a = new Uint8Array(data); | ||
var j = JSON.stringify(a); | ||
console.log(j); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |