Fork me on GitHub

Class stream.WriteStream


Defined in: stream.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
stream.WriteStream(request, options)

Writable cloud stream.

Field Summary
Field Attributes Field Name and Description
<static>  
stream.WriteStream.writable

Implements writable "A boolean that is true by default, but turns false after an 'error' occurred or end() / destroy() was called.

Method Summary
Method Attributes Method Name and Description
 

Implements destroy "Closes the underlying file descriptor.

 

Implements destroySoon "After the write queue is drained, close the file descriptor.

 
end(value, encoding)

Implements end

Terminates the stream with EOF or FIN.Argument based options:

  • end()
  • end(string, encoding)
  • end(buffer)
 
write(value, encoding)

Write string/buffer to stream.

Event Summary
Event Attributes Event Name and Description
 

Close event ('close').

 

Drain event ('drain').

 
end(results, meta)

Completion event ('end').

 
error(err)

Error event ('error').

 
pipe(src)

Pipe event ('pipe').

Class Detail
stream.WriteStream(request, options)

Writable cloud stream.

Implements Writable Stream interface.

Parameters:
{request.AuthenticatedRawRequest} request
Request object.
{Object} options Optional
Options object.
{Function} options.errorFn Optional
Function to call with error.
{Function} options.endFn Optional
Function to call with results. Called: endFn(response).
Field Detail
<static> {boolean} stream.WriteStream.writable

Implements writable "A boolean that is true by default, but turns false after an 'error' occurred or end() / destroy() was called."

Method Detail
destroy()

Implements destroy "Closes the underlying file descriptor. Stream will not emit any more events."


destroySoon()

Implements destroySoon "After the write queue is drained, close the file descriptor. destroySoon() can still destroy straight away, as long as there is no data left in the queue for writes."


end(value, encoding)

Implements end

Terminates the stream with EOF or FIN.Argument based options:

  • end()
  • end(string, encoding)
  • end(buffer)
Parameters:
{Buffer|string} value
Buffer / string to write.
{string='utf8'} encoding
Encoding to use if string value.

{boolean} write(value, encoding)

Write string/buffer to stream.

Argument based options:

  • write(string, encoding='utf8', [fd])
  • write(buffer)

Note: fd parameter is not currently supported.

Note: AWS/GSFD does not support Transfer-Encoding: chunked, so we accumulate buffers and write it all in one shot at the end() call. In the future, parallel upload might be supported.

This also means that nothing actually happens on the network until an end() is called.

Implements write "Writes string with the given encoding to the stream. Returns true if the string has been flushed to the kernel buffer. Returns false to indicate that the kernel buffer is full, and the data will be sent out in the future. The 'drain' event will indicate when the kernel buffer is empty again. The encoding defaults to 'utf8'.

If the optional fd parameter is specified, it is interpreted as an integral file descriptor to be sent over the stream. This is only supported for UNIX streams, and is silently ignored otherwise. When writing a file descriptor in this manner, closing the descriptor before the stream drains risks sending an invalid (closed) FD."

... and ...

"Same as the above except with a raw buffer."

Parameters:
{Buffer|string} value
Buffer / string to write.
{string='utf8'} encoding
Encoding to use if string value.
Returns:
{boolean} If buffer is available (always true).
Event Detail
close()

Close event ('close').

Implements Event 'close'


drain()

Drain event ('drain').

Implements Event 'drain'


end(results, meta)

Completion event ('end').

Extra event to allow caller to know that writing has been completed.

Parameters:
{Object} results
Results object.
{Object} meta
Headers, meta object.
{Object} meta.headers Optional
HTTP headers.
{Object} meta.cloudHeaders Optional
Cloud provider headers.
{Object} meta.metadata Optional
Cloud metadata.

error(err)

Error event ('error').

Implements Event 'error'

Parameters:
{Error|errors.CloudError} err
Error object.

pipe(src)

Pipe event ('pipe').

Implements Event 'pipe'

Parameters:
{Object} src
A Readable Stream object.