react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / node_modules / commoner / node_modules / iconv-lite / encodings / internal.js
81169 views"use strict"12// Export Node.js internal encodings.34module.exports = {5// Encodings6utf8: { type: "_internal", bomAware: true},7cesu8: "utf8",8unicode11utf8: "utf8",910ucs2: { type: "_internal", bomAware: true},11utf16le: "ucs2",1213binary: { type: "_internal" },14base64: { type: "_internal" },15hex: { type: "_internal" },1617// Codec.18_internal: InternalCodec,19};2021//------------------------------------------------------------------------------2223function InternalCodec(codecOptions) {24this.enc = codecOptions.encodingName;25this.bomAware = codecOptions.bomAware;2627if (this.enc === "base64")28this.encoder = InternalEncoderBase64;29}3031InternalCodec.prototype.encoder = InternalEncoder;32InternalCodec.prototype.decoder = InternalDecoder;3334//------------------------------------------------------------------------------3536// We use node.js internal decoder. It's signature is the same as ours.37var StringDecoder = require('string_decoder').StringDecoder;3839if (!StringDecoder.prototype.end) // Node v0.8 doesn't have this method.40StringDecoder.prototype.end = function() {};414243function InternalDecoder(options, codec) {44StringDecoder.call(this, codec.enc);45}4647InternalDecoder.prototype = StringDecoder.prototype;484950//------------------------------------------------------------------------------51// Encoder is mostly trivial5253function InternalEncoder(options, codec) {54this.enc = codec.enc;55}5657InternalEncoder.prototype.write = function(str) {58return new Buffer(str, this.enc);59}6061InternalEncoder.prototype.end = function() {62}636465//------------------------------------------------------------------------------66// Except base64 encoder, which must keep its state.6768function InternalEncoderBase64(options, codec) {69this.prevStr = '';70}7172InternalEncoderBase64.prototype.write = function(str) {73str = this.prevStr + str;74var completeQuads = str.length - (str.length % 4);75this.prevStr = str.slice(completeQuads);76str = str.slice(0, completeQuads);7778return new Buffer(str, "base64");79}8081InternalEncoderBase64.prototype.end = function() {82return new Buffer(this.prevStr, "base64");83}84858687