Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs stream pipeline

const { pipeline } = require('stream');
let readStream = fs.createReadStream("./myDataInput.txt");
let writeStream = fs.createWriteStream("./myDataOutput.txt");

pipeline(readStream, writeStream, error => {
   if (error) {
      console.error(error);
   } else {
      console.info("Pipeline Successful")
   }
});
Comment

nodejs stream pipeline

const fs = require('fs');
const { pipeline, Transform } = require('stream');

const readStream = fs.createReadStream("text.txt", {
    flags: 'r',
    encoding: 'utf-8',
    autoClose: true,
});

const writeStream = fs.createWriteStream("text2.txt", {
    flags: 'w',
    encoding: 'utf-8',
    autoClose: true,
});

const transformStream = new Transform({
  //Transform data to filter for even numbers
        transform(chunk, enc, cb) {
            const data = chunk.toString().split(" ").filter(value => !(parseInt(value) & 1));
            cb(null, data.join(" "));
        }
    });

pipeline(readStream, transformStream, writeStream, (err) => {
    if(err) 
        console.error(err);
    else 
        console.error("success");
  //writeStream has written only even numbers from readStream
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: show json preformatted 
Javascript :: javascript fiori 
Javascript :: react three fiber cannon collision 
Javascript :: store reference of event listener inside a element 
Javascript :: debounce getx 
Javascript :: how to get params from function js 
Javascript :: the document has mutated since the result was returned 
Javascript :: js if animation infinity end 
Javascript :: convert javascript to python 
Javascript :: change firebase email on login 
Javascript :: spread 
Javascript :: filter 
Javascript :: function generator js 
Javascript :: javascript interview questions 
Javascript :: react-scripts not found 
Javascript :: how to remove react icon from tab 
Javascript :: process node.js example 
Javascript :: for loop in js 
Javascript :: javascript document get by attribute 
Javascript :: how to download json object that come from backend in react 
Javascript :: how do you pass props between components 
Javascript :: javascript get all elements by class starting with 
Javascript :: js array to object 
Javascript :: nodejs read file to array 
Javascript :: mdn react 
Javascript :: how to clear nodejs terminal in vs code 
Javascript :: arrow function syntax vs function expression syntax 
Javascript :: id in class selector jquery 
Javascript :: Argument #1 ($client) must be of type AwsS3Client 
Javascript :: how to see javascript code in chrome 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =