
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
scramjet-core
Advanced tools
A pluggable minimal version of Scramjet that focuses only on stream transform and exposes only core features
This is the minimal, dependency free version of scramjet
used as of Scramjet
version 3.0.0 as a base for scramjet
and scramjet plugins.
Unless you are sure, you should be better off with using the main repo and module.
It is built upon the logic behind three well known javascript array operations - namingly map, filter and reduce. This means that if you've ever performed operations on an Array in JavaScript - you already know Scramjet like the back of your hand.
Scramjet uses functional programming to run transformations on your data streams in a fashion very similar to the well known event-stream node module. Most transformations are done by passing a transform function. You can write your function in three ways:
Example: a simple stream transform that outputs a stream of objects of the same id property and the length of the value string.
datastream.map(
(item) => ({id: item.id, length: item.value.length})
)
Example: A simple stream that uses Fetch API to get all the contents of all entries in the stream
datastream.map(
async (item) => fetch(item)
)
Example: A simple stream that fetches an url mentioned in the incoming object
datastream.map(
(item) => new Promise((resolve, reject) => {
request(item.url, (err, res, data) => {
if (err)
reject(err); // will emit an "error" event on the stream
else
resolve(data);
});
})
)
The actual logic of this transform function is as if you passed your function to the then
method of a Promise
resolved with the data from the input stream.
Here's the list of the exposed classes and methods, please review the specific documentation for details:
scramjet.DataStream
- the base class for all scramjet classes.scramjet.BufferStream
- a DataStream of Buffers.scramjet.StringStream
- a DataStream of Strings.scramjet.MultiStream
- a DataStream of Strings.scramjet.plugin
- method for adding plugins, please see the docsNote that:
The quick reference of the exposed classes:
A factilitation stream created for easy splitting or parsing buffers.
Useful for working on built-in Node.js streams from files, parsing binary formats etc.
A simple use case would be:
fs.createReadStream('pixels.rgba')
.pipe(new BufferStream) // pipe a buffer stream into scramjet
.breakup(4) // split into 4 byte fragments
.parse(buf => [
buf.readInt8(0), // the output is a stream of R,G,B and Alpha
buf.readInt8(1), // values from 0-255 in an array.
buf.readInt8(2),
buf.readInt8(3)
]);
Detailed BufferStream docs here
Method | Description | Example |
---|---|---|
new BufferStream(opts) | Creates the BufferStream | |
bufferStream.shift(chars, func) ⇒ BufferStream | Shift given number of bytes from the original stream | shift example |
bufferStream.split(splitter) ⇒ BufferStream | Splits the buffer stream into buffer objects | split example |
bufferStream.breakup(number) ⇒ BufferStream | Breaks up a stream apart into chunks of the specified length | breakup example |
bufferStream.stringify(encoding) ⇒ StringStream | Creates a string stream from the given buffer stream | stringify example |
bufferStream.parse(parser) ⇒ DataStream | Parses every buffer to object | parse example |
Method | Description | Example |
---|---|---|
new DataStream(opts) | Create the DataStream. | |
dataStream.map(func, Clazz) ⇒ DataStream | Transforms stream objects into new ones, just like Array.prototype.map | map example |
dataStream.filter(func) ⇒ DataStream | Filters object based on the function outcome, just like | filter example |
dataStream.reduce(func, into) ⇒ Promise | Reduces the stream into a given accumulator | reduce example |
dataStream.into(func, into) ⇒ DataStream | Pushes the data into another scramjet stream while keeping flow control and | |
dataStream.use(func) ⇒ * | Calls the passed method in place with the stream as first argument, returns result. | use example |
dataStream.tee(func) ⇒ DataStream | Duplicate the stream | tee example |
dataStream.each(func) ↩︎ | Performs an operation on every chunk, without changing the stream | |
dataStream.while(func) ⇒ DataStream | Reads the stream while the function outcome is truthy. | |
dataStream.until(func) ⇒ DataStream | Reads the stream until the function outcome is truthy. | |
dataStream.catch(callback) ↩︎ | Provides an way to catch errors in chanined streams. | |
dataStream.raise(err) ⇒ Promise | Executes all error handlers and if none resolves, then emits an error. | |
dataStream.pipe(to, options) ⇒ Writable | Override of node.js Readable pipe. | |
dataStream.bufferify(serializer) ⇒ BufferStream | Creates a BufferStream | bufferify example |
dataStream.stringify(serializer) ⇒ StringStream | Creates a StringStream | stringify example |
dataStream.run() ⇒ Promise | Consumes all stream items without doing anything | |
dataStream.toArray(initial) ⇒ Promise | Aggregates the stream into a single Array | |
dataStream.toGenerator() ⇒ Iterable.<Promise.<*>> | Returns an async generator | |
dataStream._selfInstance() ⇒ DataStream | Returns a new instance of self. | _selfInstance example |
DataStream.fromArray(arr) ⇒ DataStream | Create a DataStream from an Array | fromArray example |
DataStream.fromIterator(iter) ⇒ DataStream | Create a DataStream from an Iterator | fromIterator example |
A stream of string objects for further transformation on top of DataStream.
Detailed StringStream docs here
Method | Description | Example |
---|---|---|
new StringStream(encoding) | Constructs the stream with the given encoding | |
stringStream.shift(bytes, func) ⇒ StringStream | Shifts given length of chars from the original stream | shift example |
stringStream.split(splitter) ⇒ StringStream | Splits the string stream by the specified regexp or string | split example |
stringStream.match(splitter) ⇒ StringStream | Finds matches in the string stream and streams the match results | match example |
stringStream.toBufferStream() ⇒ StringStream | Transforms the StringStream to BufferStream | toBufferStream example |
stringStream.parse(parser) ⇒ DataStream | Parses every string to object | parse example |
StringStream.SPLIT_LINE | A handly split by line regex to quickly get a line-by-line stream | |
StringStream.fromString(str, encoding) ⇒ StringStream | Creates a StringStream and writes a specific string. |
An object consisting of multiple streams than can be refined or muxed.
Detailed MultiStream docs here
Method | Description | Example |
---|---|---|
new MultiStream(streams, options) | Crates an instance of MultiStream with the specified stream list | |
multiStream.streams : Array | Array of all streams | |
multiStream.length ⇒ number | Returns the current stream length | |
multiStream.map(aFunc) ⇒ MultiStream | Returns new MultiStream with the streams returned by the tranform. | map example |
multiStream.find(...args) ⇒ DataStream | Calls Array.prototype.find on the streams | |
multiStream.filter(func) ⇒ MultiStream | Filters the stream list and returns a new MultiStream with only the | filter example |
multiStream.mux(cmp) ⇒ DataStream | Muxes the streams into a single one | mux example |
multiStream.add(stream) | Adds a stream to the MultiStream | add example |
multiStream.remove(stream) | Removes a stream from the MultiStream | remove example |
Check out the command line interface for simplified scramjet usage with scramjet-cli
$ sjr -i http://datasource.org/file.csv ./transform-module-1 ./transform-module-1 | gzip > logs.gz
As of version 2.0 Scramjet is MIT Licensed.
The project need's your help! There's lots of work to do - transforming and muxing, joining and splitting, browserifying, modularizing, documenting and issuing those issues.
If you want to help and be part of the Scramjet team, please reach out to me, signicode on Github or email me: scramjet@signicode.com.
FAQs
A pluggable minimal version of Scramjet that focuses only on stream transform and exposes only core features
The npm package scramjet-core receives a total of 4,145 weekly downloads. As such, scramjet-core popularity was classified as popular.
We found that scramjet-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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 uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.