![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@cio/transformer
Advanced tools
Easily use a Transform pipeline to handle communication.
npm install @cio/transformer --save
Uses specified transforms in a pipeline from socket input back to socket output.
Accepts a single transform or an array of transforms.
Accepts the actual transform instance, a function to build the transform, or a string it can provide to require()
to get a builder function.
Note: A server should (very likely) use builder functions to make a new transform for each connection.
// get the `cio` module's builder function and build one
var buildCio = require('cio')
, cio = buildCio();
// provide the module name to load it for the specific type of socket
cio.onClient('@cio/transformer');
cio.onServerClient('@cio/transformer');
// OR: provide the function
var fn = require('@cio/transformer');
cio.onClient(fn);
cio.onServerClient(fn);
// shows 3 different ways to provide a transform to use.
// shows specifying a single transform and an array of them
var transformModule = 'some-module'
, buildTransform = require(transformModule)
, someTransform = buildTransform()
, optionsAsInstance = { transform: someTransform }
, optionsAsBuilder = { transform: buildTransform }
, optionsAsString = { transform: transformModule }
, optionsWithMultiple = {
// can mix any of the types
transform: [
someTransform // uses instance (not good for server)
buildTransform, // calls buildTransform()
transformModule, // does a require(), then calls function
]
};
// then create a client. these all produce the same thing:
var client = cio.client(optionsAsInstance)
, client = cio.client(optionsAsBuilder)
, client = cio.client(optionsAsString);
// does:
// client.pipe(someTransform).pipe(client)
// the string and function type will be used to get a new transform
// and then all three are piped in sequence.
var client = cio.client(optionsWithMultiple);
// final result is:
// client.pipe(someTransform).pipe(someTransform2).pipe(someTransform3).pipe(client)
There are multiple ways to build a Transform.
stream
documentation (Note, this link is for the latest Node, be sure to check for the version you're using).// standard Node way (newer versions):
// Note: this way requires splitting incoming string on newlines via another
// transform piped to this one, or, done manually in your function.
var Transform = require('stream').Transform;
function builder1(options) {
return new Transform({
transform: function (data, encoding, next) {
var string = data.toString('utf8')
, object = null;
try {
object = JSON.parse(string);
this.push(object);
next();
} catch(error) {
next({
error: 'Unable to parse string with JSON.parse()'
Error: error
});
}
}
});
}
// the through2 way:
// Note: this way requires splitting incoming string on newlines via another
// transform piped to this one, or, done manually in your function.
var thru = require('through2')
function builder2(options) {
return thru(function (data, encoding, next) {
// same processing as above in builder1.
});
}
// the transforming way:
// Note: (module is a function which accepts build options)
var transform = require('transforming')()
var builder3 = function(options) {
// simple case of transforming a newline delimited string into an object
return transform.splitStringToObject(JSON.parse);
// OR: long form without making use of defaults or convenience functions:
return transform.split('\n').string('utf8').toObject(JSON.parse);
}
FAQs
Easily use a Transform pipeline to handle communication.
The npm package @cio/transformer receives a total of 0 weekly downloads. As such, @cio/transformer popularity was classified as not popular.
We found that @cio/transformer 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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.