Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Created November 22, 2012 17:19
Show Gist options
  • Save ralphholzmann/4132223 to your computer and use it in GitHub Desktop.
Save ralphholzmann/4132223 to your computer and use it in GitHub Desktop.
Base64Stream
Stream = require "stream"
class Base64Stream extends Stream
_queue: ""
_emitChunk: ( chunk ) ->
@emit "data", new Buffer chunk, "base64"
write: ( chunk ) ->
if chunk.length % 4 != 0
@_queue += chunk
if @_queue.length % 4 == 0
@_emitChunk @_queue
@_queue = ""
else
@_emitChunk chunk
end: ( chunk ) ->
if arguments.length
@write.apply @, arguments
if @_queue.length
@_emitChunk @_queue
@emit "end"
module.exports = Base64Stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment