VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-stream-writable-writableended-property/

⇱ Node.js Stream writable.writableEnded Property - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js Stream writable.writableEnded Property

Last Updated : 12 Oct, 2021
The writable.writableEnded property is an inbuilt application programming interface of Stream module which is used to check the writable.end() method is being called or not. Syntax:
writable.writableEnded 
Return Value: It returns true if writable.end() method is being called before otherwise returns false. Below examples illustrate the use of writable.writableEnded property in Node.js: Example 1: Output:
hi
GFG
Writable {
 _writableState:
 WritableState { objectMode: false,
 highWaterMark: 16384,
 finalCalled: false,
 needDrain: false,
 ending: true,
 ended: true,
 finished: false,
 destroyed: true,
 decodeStrings: true,
 defaultEncoding: 'utf8',
 length: 0,
 writing: false,
 corked: 0,
 sync: false,
 bufferProcessing: false,
 onwrite: [Function: bound onwrite],
 writecb: null,
 writelen: 0,
 bufferedRequest: null,
 lastBufferedRequest: null,
 pendingcb: 2,
 prefinished: true,
 errorEmitted: false,
 emitClose: true,
 autoDestroy: false,
 bufferedRequestCount: 0,
 corkedRequestsFree:
 { next: null,
 entry: null,
 finish: [Function: bound onCorkedFinish] } },
 writable: false,
 _write: [Function: write],
 domain: null,
 _events: [Object: null prototype] {},
 _eventsCount: 0,
 _maxListeners: undefined }
Here, you can see that the ended property in the above example is being set to true. Example 2: Output:
hi
GFG
Writable {
 _writableState: WritableState {
 objectMode: false,
 highWaterMark: 16384,
 finalCalled: false,
 needDrain: false,
 ending: false,
 ended: false,
 finished: false,
 destroyed: true,
 decodeStrings: true,
 defaultEncoding: 'utf8',
 length: 0,
 writing: false,
 corked: 0,
 sync: false,
 bufferProcessing: false,
 onwrite: [Function: bound onwrite],
 writecb: null,
 writelen: 0,
 bufferedRequest: null,
 lastBufferedRequest: null,
 pendingcb: 2,
 prefinished: false,
 errorEmitted: false,
 emitClose: true,
 autoDestroy: false,
 bufferedRequestCount: 0,
 corkedRequestsFree:
 { next: null,
 entry: null,
 finish: [Function: bound onCorkedFinish] } },
 writable: true,
 _write: [Function: write],
 domain: null,
 _events: [Object: null prototype] {},
 _eventsCount: 0,
 _maxListeners: undefined }
In the above example the ended property is set to false because writable.end() method is not called before calling the writable.writableEnded property. Reference: https://nodejs.org/api/stream.html#stream_writable_writableended
Comment

Explore