How to use the through function from event-stream

Find comprehensive JavaScript event-stream.through code examples handpicked from public code repositorys.

event-stream.through creates a stream that acts as both a readable and writable stream, allowing data to be passed through a processing function.

153
154
155
156
157
158
159
160
161
162

watch('build/monaco/*').pipe(es.through(function() {
    runSoon(5000);
}));

resultStream = es.through(function(data) {
    const filePath = path.normalize(data.path);
    if (filesToWatchMap[filePath]) {
        runSoon(5000);
    }
fork icon50
star icon331
watch icon18

+ 7 other calls in file

32
33
34
35
36
37
38
39
40
41
        // }

        this.emit('data', file);
});

const unicode = es.through(function (file) {
        const lines = file.contents.toString('utf8').split(/\r\n|\r|\n/);
        file.__lines = lines;

        let skipNext = false;
fork icon869
star icon0
watch icon274

+ 11 other calls in file

How does event-stream.through work?

event-stream.through is a function that creates a stream through which objects can flow, and it allows the user to specify functions that can perform operations on the objects as they flow through the stream. The user can define functions to be called when an object is received, to modify the object, and to pass the modified object to the next function in the stream.

81
82
83
84
85
86
87
88
89
90
        });

        this.emit('data', file);
});

const copyrights = es.through(function (file) {
        const lines = file.__lines;

        for (let i = 0; i < copyrightHeaderLines.length; i++) {
                if (lines[i] !== copyrightHeaderLines[i]) {
fork icon869
star icon0
watch icon274

+ 11 other calls in file

28
29
30
31
32
33
34
35
36
37
  response.set('Transfer-Encoding', 'chunked');
}

var hash = crypto.createHash('md5');

return es.through(function (chunk) {
  hash.update(chunk);
  this.emit('data', chunk);
},
function () {
fork icon95
star icon656
watch icon26

+ 15 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
const es = require("event-stream");

const transformStream = es.through(function (chunk) {
  // do some transformation on the input chunk
  const transformedChunk = chunk.toUpperCase();

  // push the transformed chunk downstream
  this.emit("data", transformedChunk);
});

// use the transform stream with some input and output streams
inputStream.pipe(transformStream).pipe(outputStream);

In this example, event-stream.through is used to create a transform stream that converts all input text to uppercase. The transform function is passed as a callback to es.through, and is called for each chunk of data that passes through the stream. The transformed chunk is then pushed downstream using the emit method, and can be further processed by additional stream operations.

151
152
153
154
155
156
157
158
159
160

const hygiene = exports.hygiene = (some, options) => {
    options = options || {};
    let errorCount = 0;

    const eol = es.through(function (file) {
        if (/\r\n?/g.test(file.contents.toString('utf8'))) {
            console.error(file.relative + ': Bad EOL found');
            errorCount++;
        }
fork icon96
star icon232
watch icon17

+ 9 other calls in file

19
20
21
22
23
24
25
26
27
28

const NoCancellationToken = { isCancellationRequested: () => false };

exports.incremental = (streamProvider, initial, supportsCancellation) => {
    const input = es.through();
    const output = es.through();
    let state = 'idle';
    let buffer = Object.create(null);

    const token = !supportsCancellation ? null : { isCancellationRequested: () => Object.keys(buffer).length > 0 };
fork icon50
star icon332
watch icon18

+ 39 other calls in file

10
11
12
13
14
15
16
17
18
19
    return null;
  })
}

function filter(func) {
  return es.through(function(data) {
    if (func(data)) {
      this.emit('data', data);
    }
  })
fork icon0
star icon7
watch icon3

+ 5 other calls in file

120
121
122
123
124
125
126
127
128
129
}))
.pipe(tsFilter)
.pipe(util.loadSourcemaps())
.pipe(compilation())
.pipe(build ? nlsDev.rewriteLocalizeCalls() : es.through())
.pipe(build ? util.stripSourceMappingURL() : es.through())
.pipe(sourcemaps.write('.', {
        sourceMappingURL: !build ? null : f => `${baseUrl}/${f.relative}.map`,
        addComment: !!build,
        includeContent: !!build,
fork icon1
star icon6
watch icon7

+ 15 other calls in file

98
99
100
101
102
103
104
105
106
107
function modifyI18nPackFiles(existingTranslationFolder, resultingTranslationPaths, pseudo = false) {
    let parsePromises = [];
    let mainPack = { version: i18n.i18nPackVersion, contents: {} };
    let extensionsPacks = {};
    let errors = [];
    return es.through(function (xlf) {
        let rawResource = path.basename(xlf.relative, '.xlf');
        let resource = rawResource.substring(0, rawResource.lastIndexOf('.'));
        let contents = xlf.contents.toString();
        let parsePromise = pseudo ? i18n.XLF.parsePseudo(contents) : i18n.XLF.parse(contents);
fork icon842
star icon0
watch icon276

380
381
382
383
384
385
386
387
388
389
390
391
	'**',
	'!extensions/import/*.docx',
	'!extensions/admin-tool-ext-win/license/**'
], { restore: true });


const filelength = es.through(function (file) {


	const fileName = path.basename(file.relative);
	const fileDir = path.dirname(file.relative);
	//check the filename is < 50 characters (basename gets the filename with extension).
fork icon842
star icon0
watch icon276

288
289
290
291
292
293
294
295
296
297
298


/**
 * @param {{ (path: string): boolean }} testFunc
 */
function filterStream(testFunc) {
	return es.through(function (data) {
		if (!testFunc(data.relative)) {
			return;
		}
		this.emit('data', data);
fork icon54
star icon19
watch icon20

+ 13 other calls in file

828
829
830
831
832
833
834
835
836
837
    }
    this.emit('data', file);
});

const tsFiles = [];
const tscFilesTracker = es.through(function (file) {
    tsFiles.push(file.path.replace(/\\/g, '/'));
    tsFiles.push(file.path);
    this.emit('data', file);
});
fork icon0
star icon0
watch icon1

+ 111 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14
    util = require('util'),
    DEFAULT_READ_LENGTH = 64 * 1024; // no evidence for this value


exports.createWriteStream = function(options) {
  var client = options.client;
  return es.through(client.append.bind(client, options.key));
};


exports.createReadStream = function(options) {
  var key = new Buffer(options.key),
fork icon0
star icon0
watch icon0