How to use the Transform function from readable-stream

Find comprehensive JavaScript readable-stream.Transform code examples handpicked from public code repositorys.

8
9
10
11
12
13
14
15
16
  createTransformFunction,
  parseOptions,
} = require('../src/pino-mozlog/index');

const options = parseOptions(process.argv.slice(2));
const mozlogTransport = new Transform({
  objectMode: true,
  transform: createTransformFunction({ options }),
});
fork icon423
star icon520
watch icon53

+ 3 other calls in file

3
4
5
6
7
8
9
10
11
12
CSVParser.prototype = Object.create(stream.Transform.prototype, {
  constructor: { value: CSVParser }
});

function CSVParser(options) {
  stream.Transform.call(this, options);

  this.value = ''; //<co id="callout-streams-transform-1" />
  this.headers = [];
  this.values = [];
fork icon96
star icon191
watch icon12

5
6
7
8
9
10
11
12
13
14
var toArray = require('stream-to-array');

var readableStream = require('readable-stream');
var Readable = readableStream.Readable;
var Writable = readableStream.Writable;
var Transform = readableStream.Transform;
var PassThrough = readableStream.PassThrough;

var immutableClass = require('immutable-class');
var generalArraysEqual = immutableClass.generalArraysEqual;
fork icon62
star icon380
watch icon58

163
164
165
166
167
168
169
170
171
172
- __'finish'__:
- __'pipe'__:
- __'unpipe'__:
- __'error'__:

### stream.Transform
- __'readable'__:
- __'data'__:
- __'end'__:
- __'close'__:
fork icon46
star icon839
watch icon48

10
11
12
13
14
15
16
17
18
19

/* istanbul ignore if */
if (shouldOptimize) {
  // eslint-disable-next-line global-require
  const { optimize } = require('svgo');
  doOptimize = new Transform({
    objectMode: true,
    transform: (file, enc, cb) => {
      try {
        const optimized = optimize(file.contents.toString(enc), {
fork icon10
star icon113
watch icon7

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
  mq.addPeer(argv._[1], function (err) {
    if (err) console.error(err)
  })
} else if (argv._[0] === 'listen') {
  mq.listen()
  mq.createReadStream('unread', { live: true }).pipe(new Transform({
    objectMode: true,
    transform: function ({ from, seq, data }, enc, next) {
      console.log(`MESSAGE ${from}@${seq} ${data.toString()}`)
      mq.archive({ from, seq }, next)
fork icon2
star icon84
watch icon10

64
65
66
67
68
69
70
71
72
73

  return Through2
})

const obj = through2(function (options, transform, flush) {
  const t2 = new Transform(Object.assign({ objectMode: true, highWaterMark: 16 }, options))

  t2._transform = transform

  if (flush) {
fork icon126
star icon0
watch icon22

+ 3 other calls in file

10
11
12
13
14
15
16
17
18
19
//     cb(null, chunk);  }
// }
// const processStream = new MyTransform();


const processStream = Transform({
  transform: (chunk, encoding, callback) => {
    // console.log('.');
    process.stdout.write('.');
    callback(null, chunk);
fork icon20
star icon76
watch icon3

24
25
26
27
28
29
30
31
32
33
  translateTime: true,
  ignore: 'nodeID,ns',
  search: !error ? 'level < `40`' : undefined // Ignore higher levels than info (30)
})

const pinoPrettyTransformer = new Transform({
  transform (chunk, enc, callback) {
    chunk
      .toString()
      .split('\n')
fork icon3
star icon27
watch icon3

3
4
5
6
7
8
9
10
11
12
const decompress = require('decompress');
const PluginError = require('plugin-error');
const {Transform} = require('readable-stream');
const Vinyl = require('vinyl');

module.exports = options => new Transform({
        objectMode: true,
        async transform(file, enc, cb) {
                if (file.isNull()) {
                        cb(null, file);
fork icon9
star icon16
watch icon6

153
154
155
156
157
158
159
160
161
162
const ops = [];
let count = 0;

pipeline(
  db.createKeyStream(allRanks),
  new Transform({
    objectMode: true,
    transform(chunk, _enc, transformCallback) {
      debug('transforming key: %s', chunk);
      const op = new Delete(chunk);
fork icon0
star icon5
watch icon1

10
11
12
13
14
15
16
17
18
19
  }
  return streams
}

function getVerbose () {
  return new Transform({
    writableObjectMode: true,
    decodeStrings: false,
    transform: function (data, enc, cb) {
      setImmediate(function () { process.stdout.write(data + '\n') })
fork icon0
star icon3
watch icon2

+ 3 other calls in file

8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
  if (rs.needReadable || rs.length < rs.highWaterMark) {
    this._read(rs.highWaterMark);
  }
}


function Transform(options) {
  if (!(this instanceof Transform)) return new Transform(options);
  Duplex.call(this, options);
  this._transformState = {
    afterTransform: afterTransform.bind(this),
fork icon0
star icon0
watch icon1