Skip to content

Commit

Permalink
tests, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
DTrejo committed Mar 27, 2011
1 parent a84e056 commit 557f2d3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
15 changes: 15 additions & 0 deletions examples/example.js
@@ -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}
40 changes: 0 additions & 40 deletions test/no-file-test.js

This file was deleted.

35 changes: 35 additions & 0 deletions test/readme.md
@@ -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/).
8 changes: 4 additions & 4 deletions test/test.js
Expand Up @@ -35,17 +35,17 @@ module.exports = testCase({
streamingWrite(path, small, function() {
assert.equals(JSON.stringify(small), fs.readFileSync(path).toString('utf8')
, 'Streaming write to file with small object returns same as JSON.stringify');
fs.unlinkSync(path);
assert.done();
});
fs.unlinkSync(path);
assert.done();
}
, test_big_streaming_write: function(assert) {
path = './DELETEME.txt';
streamingWrite(path, big, function() {
assert.equals(JSON.stringify(big), fs.readFileSync(path).toString('utf8')
, 'Streaming write to file with big object returns same as JSON.stringify');
fs.unlinkSync(path);
assert.done();
});
fs.unlinkSync(path);
assert.done();
}
});

0 comments on commit 557f2d3

Please sign in to comment.