Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
@transformation/stream
Advanced tools
A package for integrating with Node streams.
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)
]
);
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"
]
);
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"]
);
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"
);
FAQs
Transformations for working with Node streams
The npm package @transformation/stream receives a total of 7,148 weekly downloads. As such, @transformation/stream popularity was classified as popular.
We found that @transformation/stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.