https://github.com/awinterman/format-stream
read from one stream for a while, then read from another stream, then the first stream again.
https://github.com/awinterman/format-stream
Last synced: 11 months ago
JSON representation
read from one stream for a while, then read from another stream, then the first stream again.
- Host: GitHub
- URL: https://github.com/awinterman/format-stream
- Owner: AWinterman
- Created: 2013-09-02T00:06:16.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-09-08T02:17:07.000Z (almost 13 years ago)
- Last Synced: 2025-07-09T20:36:54.542Z (12 months ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Format-Stream #
A streaming simple formatter.
## API ##
```javascript
var format = new Format(token, stream)
```
`format` is a transform stream that checks if each chunk of data matches the
token. If it does not, then the chunk is passed through. Otherwise, `format`
emits data from the second argument, `stream` until it is consumed.
## Example ##
Suppose you have a file called `base-template.html`:
```html
"Your app!"
{{welcome}}
```
And one called `welcome-template.html`.
```
"Hey you party people!"
```
In index.js you write:
```javascript
var Sentinal = require('sentinal-stream')
, Format = require('format-stream')
, token = '{{welcome}}'
var inside_stream = fs.createReadStream('welcome-template.html')
, outside_stream = fs.createReadStream('base-template.html')
// Make sure any instance of {{welcome}} is emitted in its
// own data event
var tokenizer = new Sentinal(new Buffer(token))
, format = new Format(token, inside_stream)
outside_stream
.pipe(tokenizer)
.pipe(format)
.pipe(process.stdout)
```
Then `node index.js` will print:
```
"Your app!"
"Hey you party people!"
```