Detalhes do pacote

@transformation/stream

sunesimonsen125.6kMIT7.0.2

Transformations for working with Node streams

transformation,automation,pipeline,stream,io

readme (leia-me)

@transformation/stream

A package for integrating with Node streams.

concat

Concatenates all of output of a stream into a string.

const { concat } = require("@transformation/stream");
await expect(pipeline(toFileStream(testFile), concat()), "to yield items", [
  fs.readFileSync(testFile, "utf8"),
]);

fromFileStream

Emits all chunks from a Node readable file stream.

Notice this step won't take any input, it only outputs the given items.

const { fromFileStream } = require("@transformation/stream");
const { Chunk } = require("@transformation/stream");

await expect(fromFileStream(testFile, { encoding: "utf8" }), "to yield items", [
  new Chunk(fs.readFileSync(testFile, "utf8"), "utf8"),
]);

fromStream

Emits all chunks or values of one or more Node readable streams.

Notice this step won't take any input, it only outputs the given items.

const { fromStream } = require("@transformation/stream");

When given an encoded stream the data in the chunks is strings.

const { Chunk } = require("@transformation/stream");

await expect(
  fromStream(fs.createReadStream(testFile, { encoding: "utf8" })),
  "to yield items",
  [new Chunk(fs.readFileSync(testFile, "utf8"), "utf8")]
);

If no encoding is given the data is buffers.

const { Chunk } = require("@transformation/stream");

await expect(fromStream(fs.createReadStream(testFile)), "to yield items", [
  new Chunk(fs.readFileSync(testFile), null),
]);

In case the stream is in object mode, like a byline stream, it emits all of the objects.

const byline = require("byline");

await expect(
  fromStream(byline(fs.createReadStream("song.txt"), { encoding: "utf8" })),
  "to yield items",
  [
    "One little sheep",
    "Two little birds",
    "Three little pigs",
    "Four little hedgehogs",
    "Five little hippos",
    "Six little frogs",
    "Seven little worms",
    "Eight little turtles",
    "Nine little lions",
    "Ten chickens",
  ]
);

When given multiple streams each stream will be fully flushed before continuing to the next.

const { Chunk } = require("@transformation/stream");

await expect(
  fromStream(fs.createReadStream(testFile), fs.createReadStream(testFile)),
  "to yield items",
  [
    new Chunk(fs.readFileSync(testFile), null),
    new Chunk(fs.readFileSync(testFile), null),
  ]
);

lines

Emits all of the lines of the incoming strings or chunks.

const { lines } = require("@transformation/stream");
await expect(
  fromStream(fs.createReadStream("song.txt"), lines()),
  "to yield items",
  [
    "One little sheep",
    "Two little birds",
    "Three little pigs",
    "Four little hedgehogs",
    "Five little hippos",
    "Six little frogs",
    "Seven little worms",
    "Eight little turtles",
    "Nine little lions",
    "Ten chickens",
  ]
);

You can also specify the separator that is used to split lines, it can be a string, a regex or a byte.

await expect(
  pipeline(
    spawn("find", [".", "-name", "*.txt", "-print0"], { cwd: testDir }),
    lines(0),
    skipLast()
  ),
  "to yield items",
  ["./2.txt", "./0.txt", "./1.txt"]
);

pipe

Pipes all items of the pipeline through a Node transform stream.

const { pipe } = require("transformation/stream");

Let's say we want to pipe all chunks of a file through the byline transform stream to upload the lines of the file.

const { LineStream } = require("byline");

await expect(
  pipeline(
    fromStream(fs.createReadStream("æøå.txt", { encoding: "utf8" })),
    pipe(new LineStream())
  ),
  "to yield items",
  ["Æble", "og", "blåbær", "grød", "er", "lækkert!"]
);

If you pipe strings into a transform stream, they will be interpreted as UTF-8 chunks.

await expect(
  pipeline(
    emitItems("one\ntwo\n", "three", "\nfour\nfive"),
    pipe(new LineStream())
  ),
  "to yield items",
  ["one", "two", "three", "four", "five"]
);

toFileStream

Writes all items to a Node writable file stream as a side-effect.

Notice that the items will continue through the rest of the pipeline.

const { toFileStream } = require("transformation/stream");

Let's write some lines to an output file.

await program(
  emitItems("one", "two", "three"),
  interleave("\n"),
  toFileStream(outputFile)
);

expect(await readFile(outputFile, "utf8"), "to equal", "one\ntwo\nthree");

toStream

Writes all items to a Node writable stream as a side-effect.

Notice that the items will continue through the rest of the pipeline.

const { toStream } = require("transformation/stream");

Let's say we want to add line numbers to all lines in a file and write is back out to another file. We can do that the following way.

await program(
  fromStream(fs.createReadStream("count.txt")),
  lines(),
  map((line, i) => `${i}) ${line}`),
  interleave("\n"),
  toStream(fs.createWriteStream(outputFile))
);

expect(
  await readFile(outputFile, "utf8"),
  "to equal",
  "0) one\n1) two\n2) three"
);

changelog (log de mudanças)

v7.0.1 (2022-12-06)

Pull requests

Commits to master

v7.0.0 (2022-12-06)

Pull requests

Commits to master

v6.1.0 (2022-12-06)

Pull requests

Commits to master

v6.0.1 (2022-11-23)

Pull requests

Commits to master

v6.0.0 (2022-05-31)

Pull requests

Commits to master

v5.1.1 (2022-05-31)

Pull requests

Commits to master

v5.1.0 (2022-05-31)

Pull requests

Commits to master

v5.0.0 (2022-05-30)

Pull requests

Commits to master

v4.3.0 (2022-02-08)

Pull requests

Commits to master

v4.2.0 (2022-01-17)

Pull requests

Commits to master

v4.1.2 (2021-10-07)

Pull requests

Commits to master

v4.1.1 (2021-09-17)

v4.1.0 (2021-09-17)

Pull requests

Commits to master

v4.0.1 (2021-08-18)

Pull requests

Commits to master

v4.0.0 (2021-03-16)

Pull requests

Commits to master

v3.8.0 (2020-11-12)

Pull requests

Commits to master

v3.7.0 (2020-11-10)

Pull requests

Commits to master

v3.6.0 (2020-11-08)

Pull requests

Commits to master

v3.5.3 (2020-11-08)

v3.5.2 (2020-11-07)

Pull requests

Commits to master

v3.5.1 (2020-11-06)

Pull requests

Commits to master

v3.5.0 (2020-11-06)

Pull requests

Commits to master

v3.4.0 (2020-11-05)

Pull requests

Commits to master

v3.3.0 (2020-11-04)

Pull requests

Commits to master

v3.2.0 (2020-11-03)

Pull requests

Commits to master

v3.1.0 (2020-11-01)

Pull requests

Commits to master

v3.0.0 (2020-11-01)

Pull requests

  • #47 Default to map instead of flatMap for plain functions in a pipeline (Major) (Sune Simonsen)

Commits to master

v2.3.0 (2020-11-01)

Pull requests

Commits to master

v2.2.0 (2020-10-31)

Pull requests

Commits to master

v2.1.0 (2020-10-31)

Pull requests

Commits to master

v2.0.0 (2020-10-31)

Pull requests

Commits to master

v1.34.0 (2020-10-28)

Pull requests

Commits to master

v1.33.0 (2020-09-11)

v1.32.0 (2020-08-11)

Pull requests

Commits to master

v1.31.0 (2020-07-12)

Pull requests

Commits to master

v1.30.2 (2020-07-10)

Pull requests

Commits to master

v1.30.1 (2020-07-08)

Pull requests

Commits to master

v1.30.0 (2020-07-03)

Pull requests

Commits to master

v1.29.1 (2020-07-02)

v1.29.0 (2020-07-02)

Pull requests

Commits to master

v1.28.0 (2020-07-02)

Pull requests

Commits to master

v1.27.1 (2020-06-21)

v1.27.0 (2020-06-21)

Pull requests

Commits to master

v1.26.0 (2020-06-14)

Pull requests

Commits to master

v1.25.0 (2020-06-13)

Pull requests

Commits to master

v1.24.0 (2020-06-12)

Pull requests

Commits to master

v1.23.0 (2020-06-10)

Pull requests

Commits to master

v1.22.0 (2020-06-09)

v1.21.0 (2020-06-08)

Pull requests

Commits to master

v1.20.2 (2020-06-07)

v1.20.1 (2020-06-07)

v1.20.0 (2020-06-07)

Pull requests

Commits to master

v1.19.0 (2020-06-05)

Pull requests

Commits to master

v1.18.2 (2020-06-01)

v1.18.1 (2020-06-01)

v1.18.0 (2020-06-01)

Pull requests

Commits to master

v1.17.0 (2020-05-30)

Pull requests

Commits to master

v1.16.0 (2020-05-29)

Pull requests

Commits to master

v1.15.0 (2020-05-09)

Pull requests

Commits to master

v1.14.1 (2020-04-10)

v1.14.0 (2020-02-10)

v1.13.0 (2020-02-10)

v1.12.3 (2020-02-03)

v1.12.2 (2020-01-18)

v1.12.1 (2020-01-17)

v1.12.0 (2020-01-17)

v1.11.0 (2020-01-17)

v1.10.0 (2020-01-15)

v1.9.1 (2020-01-04)

v1.9.0 (2020-01-04)

v1.8.0 (2020-01-03)

v1.7.1 (2019-12-29)

v1.7.0 (2019-12-29)

v1.6.0 (2019-12-25)

v1.5.0 (2019-12-23)

v1.4.1 (2019-12-23)

v1.4.0 (2019-12-23)

v1.3.1 (2019-12-21)

v1.3.0 (2019-12-21)

v1.2.0 (2019-12-21)

v1.1.1 (2019-12-18)

v1.1.0 (2019-12-18)