https://github.com/seangenabe/preface
Prepend data to a file.
https://github.com/seangenabe/preface
stream
Last synced: 27 days ago
JSON representation
Prepend data to a file.
- Host: GitHub
- URL: https://github.com/seangenabe/preface
- Owner: seangenabe
- License: mit
- Created: 2015-08-04T15:32:19.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2022-07-06T08:13:31.000Z (over 3 years ago)
- Last Synced: 2024-04-28T01:44:43.599Z (over 1 year ago)
- Topics: stream
- Language: JavaScript
- Size: 379 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Preface
Prepend data to a stream or file.
[](https://github.com/seangenabe/preface/actions/workflows/node.js.yml)
## API
```javascript
const preface = require('preface')
const PrependStream = require('preface').PrependStream
```### class PrependStream extends Transform
A transform stream that prepends data to the incoming stream.
#### `new PrependStream(data, options)`
Creates a new instance of PrependStream.
* `data: String|Buffer|null`: The data to prepend to the input stream. Can accept any object in [object mode](https://nodejs.org/api/stream.html#stream_object_mode).
* `options: Object`: Options to pass to the [Transform constructor](https://nodejs.org/api/stream.html#stream_new_stream_transform_options).
* `options.enc: String`: Encoding of the data to push.### `preface(inputStream, data, [options])`
Returns a new instance of PrependStream constructed with the specified
arguments. This is in a way just a function version to set up the PrependStream
class.* `inputStream: stream.Readable` (or any Readable-compatible API)
* `data: String|Buffer|null` or `any`: Data to prepend to the stream. Can accept any object in [object mode](https://nodejs.org/api/stream.html#stream_object_mode).
* `options: Object`: options to pass to the PrependStream constructor.## CLI
Install as a global module to do some awesome:
* First unnamed argument: Data to prepend to the stream.
* `-i` / `--in`: Path to input file. Uses standard input if not provided.
* `-o` / `--out`: Path to output file. Uses standard output if not provided.Examples:
* `echo 1234 | preface abcd` (Try this one!)
* `preface abcd < in.txt > out.txt`
* `preface abcd --in in.txt --out out.txt`## License
MIT