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
Showing
4 changed files
with
54 additions
and
44 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,15 @@ | ||
var assert = require('assert') | ||
, streamify = require('../streamify').streamify | ||
, streamingWrite = require('../streamify').streamingWrite | ||
, fs = require('fs') | ||
, object = { a: 1, b: 2, c: 3} | ||
|
||
var str = ''; | ||
streamify(object, function(data) { str += data; }); | ||
console.log(str); | ||
// => {"a":1,"b":2,"c":3} | ||
|
||
var str = ''; | ||
streamingWrite('./ACOOLFILE.txt', object, function(data) { str += data; }); | ||
console.log(fs.readFileSync('./ACOOLFILE')); | ||
// => {"a":1,"b":2,"c":3} |
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
# JSON Streamify | ||
|
||
A streaming version of `JSON.stringify`. | ||
|
||
## Methods | ||
|
||
### `streamify(object, function)` | ||
|
||
Passes the function chunks of the object until there is none of the object left. | ||
`streamify` is a synchronous function. | ||
|
||
var assert = require('assert') | ||
, streamify = require('../streamify').streamify | ||
, streamingWrite = require('../streamify').streamingWrite | ||
, fs = require('fs') | ||
, object = { a: 1, b: 2, c: 3} | ||
|
||
var str = ''; | ||
streamify(object, function(data) { str += data; }); | ||
console.log(str); | ||
// => {"a":1,"b":2,"c":3} | ||
|
||
### `streamingWrite(filepath, object, callback)` | ||
|
||
Writes chunks of the object to the given filepath until there is none of the object left. | ||
When it finishes, it calls `callback`. | ||
|
||
var str = ''; | ||
streamingWrite('./ACOOLFILE.txt', object, function(data) { str += data; }, function() { | ||
|
||
console.log(fs.readFileSync('./ACOOLFILE')); | ||
// => {"a":1,"b":2,"c":3} | ||
}); | ||
|
||
Most of this was written by [James Halliday](http://substack.net), with a few small things by [David Trejo](http://dtrejo.com/). |
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