Sha256: 08d32b7b805ad7b41143f43783050569c35fba629d93965fc146b56aae0c1c54

Contents?: true

Size: 1.97 KB

Versions: 20

Compression:

Stored size: 1.97 KB

Contents

// Export Node.js internal encodings.

var utf16lebom = new Buffer([0xFF, 0xFE]);

module.exports = {
    // Encodings
    utf8:   { type: "_internal", enc: "utf8" },
    cesu8:  { type: "_internal", enc: "utf8" },
    unicode11utf8: { type: "_internal", enc: "utf8" },
    ucs2:   { type: "_internal", enc: "ucs2", bom: utf16lebom },
    utf16le:{ type: "_internal", enc: "ucs2", bom: utf16lebom },
    binary: { type: "_internal", enc: "binary" },
    base64: { type: "_internal", enc: "base64" },
    hex:    { type: "_internal", enc: "hex" },

    // Codec.
    _internal: function(options) {
        if (!options || !options.enc)
            throw new Error("Internal codec is called without encoding type.")

        return {
            encoder: options.enc == "base64" ? encoderBase64 : encoderInternal,
            decoder: decoderInternal,

            enc: options.enc,
            bom: options.bom,
        };
    },
};

// We use node.js internal decoder. It's signature is the same as ours.
var StringDecoder = require('string_decoder').StringDecoder;

if (!StringDecoder.prototype.end) // Node v0.8 doesn't have this method.
    StringDecoder.prototype.end = function() {};

function decoderInternal() {
    return new StringDecoder(this.enc);
}

// Encoder is mostly trivial

function encoderInternal() {
    return {
        write: encodeInternal,
        end: function() {},
        
        enc: this.enc,
    }
}

function encodeInternal(str) {
    return new Buffer(str, this.enc);
}


// Except base64 encoder, which must keep its state.

function encoderBase64() {
    return {
        write: encodeBase64Write,
        end: encodeBase64End,

        prevStr: '',
    };
}

function encodeBase64Write(str) {
    str = this.prevStr + str;
    var completeQuads = str.length - (str.length % 4);
    this.prevStr = str.slice(completeQuads);
    str = str.slice(0, completeQuads);

    return new Buffer(str, "base64");
}

function encodeBase64End() {
    return new Buffer(this.prevStr, "base64");
}

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
gulp_assets-1.0.0.pre.5 template/node_modules/gulp-livereload/node_modules/tiny-lr/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
gulp_assets-1.0.0.pre.4 template/node_modules/gulp-livereload/node_modules/tiny-lr/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
gulp_assets-1.0.0.pre.3 template/node_modules/gulp-livereload/node_modules/tiny-lr/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/node_modules/iconv-lite/encodings/internal.js