preface
v3.0.2-0
Published
Prepend data to a stream or file.
Readme
Preface
Prepend data to a stream or file.
API
import { preface, createPrependGenerator, PrependStream } from "preface"createPrependGenerator(data)
Create an async generator that prepends data to the incoming stream or async iterable.
Example
import { pipeline } from "node:stream/promises"
const r = new PassThrough()
const g = createPrependGenerator("b")
const w = new PassThrough()
const p = pipeline(r, g, w)
r.end("a")
await p
// w should now hold "ab"class PrependStream extends Transform
Deprecated: use createPrependGenerator instead.
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.options: Object: Options to pass to the Transform constructor.options.enc: String: Encoding of the data to push.
preface<T>(inputStream, data)
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: AsyncIterable | Iterable<T>data: T: Data to prepend to the stream. Can accept any object in object mode.
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.txtpreface abcd --in in.txt --out out.txt
License
MIT
