var alphabet = '0123456789abcdefghjkmnpqrtuvwxyz'
var alias = { o:0, i:1, l:1, s:5 }

var lookup = function() {
    var table = {}
    for (var i = 0; i < alphabet.length; i++) {
        table[alphabet[i]] = i
    }
    for (var key in alias) {
        if (!alias.hasOwnProperty(key)) continue
        table[key] = table['' + alias[key]]
    }
    lookup = function() { return table }
    return table
}

Number.prototype.toBinary = function(places) {
    if (!places) places = 0
    var val = this + 0
    var str = ''
    while (val || places > 0) {
        str = ((val & 1) ? '1' : '0') + str
        val >>= 1
        places--
    }
    return str
}

function Encoder() {
    var skip = 0 // how many bits we will skip from the first byte
    var bits = 0 // 5 high bits, carry from one byte to the next

    this.output = ''

    this.readByte = function(byte) {
        // coerce the byte to an int
        if (typeof byte == 'string') byte = byte.charCodeAt(0)
        //console.log(byte.toBinary(8) + ' > s ' + skip)

        if (skip < 0) { // we have a carry from the previous byte
            //console.log('carry ' + bits.toBinary(8))
            bits |= (byte >> (-skip))
        } else { // no carry
            bits = (byte << skip) & 248
        }

        if (skip > 3) {
            // not enough data to produce a character, get us another one
            skip -= 8
            return 1
        }

        if (skip < 4) {
            // produce a character
            //console.log('         > ' + (bits >> 3).toBinary(5))
            this.output += alphabet[bits >> 3]
            skip += 5
        }

        return 0
    }

    this.finish = function(check) {
        var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
        this.output = ''
        return output
    }
}

Encoder.prototype.update = function(input) {
    for (var i = 0; i < input.length; ) {
        i += this.readByte(input[i])
    }
    var output = this.output
    this.output = ''
    return output
}

function Decoder() {
    var skip = 0 // how many bits we have from the previous character
    var byte = 0 // current byte we're producing

    this.output = ''

    // consume a character from the stream
    this.readChar = function(char) {
        //console.log('Read: ' + char + ' \tPos: ' + skip + ' \tCarry: ' + byte)
        if (typeof char != 'string'){
            if (typeof char == 'number') {
                char = String.fromCharCode(char)
            }
        }
        char = char.toLowerCase()
        var val = lookup()[char]
        if (typeof val == 'undefined') {
            // character does not exist in our lookup table
            return
            throw Error('Could not find character "' + char + '" in lookup table.')
        }
        //console.log(' Val: ' + val + ' 0b' + val.toBinary())
        val <<= 3 // move to the high bits
        
        byte |= val >>> skip
        //console.log(' Update: ' + byte.toBinary())
        skip += 5
        
        if (skip >= 8) {
            //console.log(' Produce: ' + byte.toBinary())

            this.output += String.fromCharCode(byte)
            skip -= 8
            if (skip > 0) byte = (val << (5 - skip)) & 255
            else byte = 0
            //console.log(' Left: ' + byte.toBinary())
        }

    }

    this.finish = function(check) {
        var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
        this.output = ''
        return output
    }
}

Decoder.prototype.update = function(input) {
    for (var i = 0; i < input.length; i++) {
        this.readChar(input[i])
    }
    var output = this.output
    this.output = ''
    return output
}

function decode(input) {
    decoder = new Decoder()
    var output = decoder.update(input) + decoder.finish()
    return output
}

function encode(input) {
    encoder = new Encoder()
    var output = encoder.update(input) + encoder.finish()
    return output
}

var crypto, fs
function sha1(input, cb) {
    if (typeof crypto == 'undefined') crypto = require('crypto')
    var hash = crypto.createHash('sha1')
    hash.digest = (function(digest) {
        return function() {
            return encode(digest.call(this, 'binary'))
        }
    })(hash.digest)
    if (cb) { // streaming
        if (typeof input == 'string' || Buffer.isBuffer(input)) {
            try {
                return cb(null, sha1(input))
            } catch (err) {
                return cb(err, null)
            }
        }
        if (!typeof input.on == 'function') return cb({ message: "Not a stream!" })
        input.on('data', function(chunk) { hash.update(chunk) })
        input.on('end', function() { cb(null, hash.digest()) })
        return
    }

    // non-streaming
    if (input) {
        return hash.update(input).digest()
    }
    return hash
}
sha1.file = function(filename, cb) {
    if (filename == '-') {
        process.stdin.resume()
        return sha1(process.stdin, cb)
    }
    if (typeof fs == 'undefined') fs = require('fs')
    return fs.stat(filename, function(err, stats) {
        if (err) return cb(err, null)
        if (stats.isDirectory()) return cb({ dir: true, message: "Is a directory" })
        return sha1(require('fs').createReadStream(filename), cb)
    })
}

module.exports = {
    Decoder: Decoder,
    Encoder: Encoder,
    encode: encode,
    decode: decode,
    sha1: sha1
}

@@ -1859,32 +1859,39 @@
 = function(input
+, flush
 ) %7B%0A    for (var
@@ -2005,32 +2005,85 @@
 his.output = ''%0A
+    if (flush) %7B%0A      output += this.finish()%0A    %7D%0A
     return outpu
@@ -3610,24 +3610,31 @@
 nction(input
+, flush
 ) %7B%0A    for 
@@ -3754,24 +3754,77 @@
 output = ''%0A
+    if (flush) %7B%0A      output += this.finish()%0A    %7D%0A
     return o
@@ -3926,27 +3926,14 @@
 nput
-) + decoder.finish(
+, true
 )%0A  
@@ -3976,18 +3976,16 @@
 nput) %7B%0A
-  
   encode
@@ -3996,34 +3996,32 @@
 new Encoder()%0A  
- 
- 
 var output = enc
@@ -4041,31 +4041,16 @@
 nput
-) + encoder.finish()%0A  
+, true)%0A
   re

Add flush option to update() methods