“NodeJS Stream” Kod odpowiedzi

NodeJS tworzą strumień

const { Readable } = require("stream")

const readable = Readable.from(["input string"])

readable.on("data", (chunk) => {
  console.log(chunk) // will be called once with `"input string"`
})
North Bear

Węzeł strumieniowy JS

const fs = require('fs');
const r = fs.createReadStream('file.txt');
const z = zlib.createGzip();
const w = fs.createWriteStream('file.txt.gz');
r.pipe(z).pipe(w);
Homely Hamster

NodeJS Stream

const stream = require('stream')
const fs = require('fs')

const html = "<h1> Hello Wordl </h1>

// read file from string and write file
const stream = new Stream()
stream.pipe = function (dest) {
  dest.write(html)
  return dest
}
stream.pipe(createWriteStream(resolve(process.cwd(), 'index.html'), 'utf8'))

// read file from directory and write file
fs.createReadStream('testing.html')
 .pipe(createWriteStream(resolve(process.cwd(), 'index.html'), 'utf8'))
Restu Wahyu Saputra

NODJS: Stream dla dużego pliku

// Use stream: for big file

const fs = require('fs');

const readStream = fs.createReadStream('./doc/custom_button.dart', {encoding: 'utf-8'});    // Create:  createReadStream()
const writeStream = fs.createWriteStream('./doc/get_code.dart')             // Create  createWriteStream()

        // Method 1

// readStream.on('data', (chunkData) => {
//     console.log('----- NEW CHUNK -----');
//     console.log(chunkData);

//     // add code to new file
//     writeStream.write(chunkData);       // Write code
    
// });

        // Method 2:  Use  Pipe for jon method : read and write
readStream.pipe(writeStream);

Sore Sardine

Odpowiedzi podobne do “NodeJS Stream”

Pytania podobne do “NodeJS Stream”

Więcej pokrewnych odpowiedzi na “NodeJS Stream” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu