Node.js Akış Modülü

❮ Dahili Modüller


Örnek

Yazılabilir bir akışa yazın:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.write('Hello World!');
  res.end();
}).listen(8080);

Tanım ve Kullanım

Akış modülü, akış verilerini işlemenin bir yolunu sağlar.

İki tür akış vardır: okunabilir ve yazılabilir.

Okunabilir bir akış örneği , http.createServer() yöntemiyle çalışırken aldığınız yanıt nesnesidir.

Yazılabilir bir akış örneği , http.createServer() yöntemiyle çalışırken aldığınız istek nesnesidir.


Sözdizimi

Bazı yöntemler, http.createServer() gibi okunabilir/yazılabilir bir akış nesnesi döndürür ve bu durumda, akış modülünü eklemeniz gerekmez.

Aksi takdirde, uygulamanıza Akış modülünü dahil etmek için sözdizimi:

var stream = require('stream');

Okunabilir Akış Özellikleri ve Yöntemleri

Method Description
isPaused() Returns true if the state of  the readable stream is paused, otherwise false
pause() Pauses the readable stream
pipe() Turns the readable stream into the specified writable stream
read() Returns a specified part of the readable stream
resume() Resumes a paused stream
setEncoding() Sets the character encoding of the readable stream
unpipe() Stops turning a readable stream into a writable stream, caused by the pipe() method
unshift() Pushes some specified data back into the internal buffer
wrap() Helps reading streams made by older Node.js versions

Yazılabilir Akış Özellikleri ve Yöntemleri

Method Description
cork() Stops the writable stream and all written data will be buffered in memory
end() Ends the writable stream
setDefaultEncoding() Sets the encoding for the writable stream
uncork() Flushes all data that has been buffered since the cork() method was called
write() Writes data to the stream

❮ Dahili Modüller