diff options
| author | NateN1222 <nathannichols454@gmail.com> | 2017-09-03 17:38:26 -0500 | 
|---|---|---|
| committer | NateN1222 <nathannichols454@gmail.com> | 2017-09-03 17:38:26 -0500 | 
| commit | d324474467727fa31c76c206acb027acd8925fa1 (patch) | |
| tree | 85093616781ce3705568153c1a09d0e2b7ec5a4e /hash_script/node_modules/iconv-lite/lib | |
| parent | 7ea4ef16ca69ea37b87ca9a9306d2fd9c136539d (diff) | |
Implemented a default whitelist
Diffstat (limited to 'hash_script/node_modules/iconv-lite/lib')
| -rw-r--r-- | hash_script/node_modules/iconv-lite/lib/bom-handling.js | 52 | ||||
| -rw-r--r-- | hash_script/node_modules/iconv-lite/lib/extend-node.js | 215 | ||||
| -rw-r--r-- | hash_script/node_modules/iconv-lite/lib/index.d.ts | 24 | ||||
| -rw-r--r-- | hash_script/node_modules/iconv-lite/lib/index.js | 148 | ||||
| -rw-r--r-- | hash_script/node_modules/iconv-lite/lib/streams.js | 121 | 
5 files changed, 560 insertions, 0 deletions
diff --git a/hash_script/node_modules/iconv-lite/lib/bom-handling.js b/hash_script/node_modules/iconv-lite/lib/bom-handling.js new file mode 100644 index 0000000..1050872 --- /dev/null +++ b/hash_script/node_modules/iconv-lite/lib/bom-handling.js @@ -0,0 +1,52 @@ +"use strict"; + +var BOMChar = '\uFEFF'; + +exports.PrependBOM = PrependBOMWrapper +function PrependBOMWrapper(encoder, options) { +    this.encoder = encoder; +    this.addBOM = true; +} + +PrependBOMWrapper.prototype.write = function(str) { +    if (this.addBOM) { +        str = BOMChar + str; +        this.addBOM = false; +    } + +    return this.encoder.write(str); +} + +PrependBOMWrapper.prototype.end = function() { +    return this.encoder.end(); +} + + +//------------------------------------------------------------------------------ + +exports.StripBOM = StripBOMWrapper; +function StripBOMWrapper(decoder, options) { +    this.decoder = decoder; +    this.pass = false; +    this.options = options || {}; +} + +StripBOMWrapper.prototype.write = function(buf) { +    var res = this.decoder.write(buf); +    if (this.pass || !res) +        return res; + +    if (res[0] === BOMChar) { +        res = res.slice(1); +        if (typeof this.options.stripBOM === 'function') +            this.options.stripBOM(); +    } + +    this.pass = true; +    return res; +} + +StripBOMWrapper.prototype.end = function() { +    return this.decoder.end(); +} + diff --git a/hash_script/node_modules/iconv-lite/lib/extend-node.js b/hash_script/node_modules/iconv-lite/lib/extend-node.js new file mode 100644 index 0000000..a120400 --- /dev/null +++ b/hash_script/node_modules/iconv-lite/lib/extend-node.js @@ -0,0 +1,215 @@ +"use strict"; +var Buffer = require("buffer").Buffer; + +// == Extend Node primitives to use iconv-lite ================================= + +module.exports = function (iconv) { +    var original = undefined; // Place to keep original methods. + +    // Node authors rewrote Buffer internals to make it compatible with +    // Uint8Array and we cannot patch key functions since then. +    iconv.supportsNodeEncodingsExtension = !(new Buffer(0) instanceof Uint8Array); + +    iconv.extendNodeEncodings = function extendNodeEncodings() { +        if (original) return; +        original = {}; + +        if (!iconv.supportsNodeEncodingsExtension) { +            console.error("ACTION NEEDED: require('iconv-lite').extendNodeEncodings() is not supported in your version of Node"); +            console.error("See more info at https://github.com/ashtuchkin/iconv-lite/wiki/Node-v4-compatibility"); +            return; +        } + +        var nodeNativeEncodings = { +            'hex': true, 'utf8': true, 'utf-8': true, 'ascii': true, 'binary': true,  +            'base64': true, 'ucs2': true, 'ucs-2': true, 'utf16le': true, 'utf-16le': true, +        }; + +        Buffer.isNativeEncoding = function(enc) { +            return enc && nodeNativeEncodings[enc.toLowerCase()]; +        } + +        // -- SlowBuffer ----------------------------------------------------------- +        var SlowBuffer = require('buffer').SlowBuffer; + +        original.SlowBufferToString = SlowBuffer.prototype.toString; +        SlowBuffer.prototype.toString = function(encoding, start, end) { +            encoding = String(encoding || 'utf8').toLowerCase(); + +            // Use native conversion when possible +            if (Buffer.isNativeEncoding(encoding)) +                return original.SlowBufferToString.call(this, encoding, start, end); + +            // Otherwise, use our decoding method. +            if (typeof start == 'undefined') start = 0; +            if (typeof end == 'undefined') end = this.length; +            return iconv.decode(this.slice(start, end), encoding); +        } + +        original.SlowBufferWrite = SlowBuffer.prototype.write; +        SlowBuffer.prototype.write = function(string, offset, length, encoding) { +            // Support both (string, offset, length, encoding) +            // and the legacy (string, encoding, offset, length) +            if (isFinite(offset)) { +                if (!isFinite(length)) { +                    encoding = length; +                    length = undefined; +                } +            } else {  // legacy +                var swap = encoding; +                encoding = offset; +                offset = length; +                length = swap; +            } + +            offset = +offset || 0; +            var remaining = this.length - offset; +            if (!length) { +                length = remaining; +            } else { +                length = +length; +                if (length > remaining) { +                    length = remaining; +                } +            } +            encoding = String(encoding || 'utf8').toLowerCase(); + +            // Use native conversion when possible +            if (Buffer.isNativeEncoding(encoding)) +                return original.SlowBufferWrite.call(this, string, offset, length, encoding); + +            if (string.length > 0 && (length < 0 || offset < 0)) +                throw new RangeError('attempt to write beyond buffer bounds'); + +            // Otherwise, use our encoding method. +            var buf = iconv.encode(string, encoding); +            if (buf.length < length) length = buf.length; +            buf.copy(this, offset, 0, length); +            return length; +        } + +        // -- Buffer --------------------------------------------------------------- + +        original.BufferIsEncoding = Buffer.isEncoding; +        Buffer.isEncoding = function(encoding) { +            return Buffer.isNativeEncoding(encoding) || iconv.encodingExists(encoding); +        } + +        original.BufferByteLength = Buffer.byteLength; +        Buffer.byteLength = SlowBuffer.byteLength = function(str, encoding) { +            encoding = String(encoding || 'utf8').toLowerCase(); + +            // Use native conversion when possible +            if (Buffer.isNativeEncoding(encoding)) +                return original.BufferByteLength.call(this, str, encoding); + +            // Slow, I know, but we don't have a better way yet. +            return iconv.encode(str, encoding).length; +        } + +        original.BufferToString = Buffer.prototype.toString; +        Buffer.prototype.toString = function(encoding, start, end) { +            encoding = String(encoding || 'utf8').toLowerCase(); + +            // Use native conversion when possible +            if (Buffer.isNativeEncoding(encoding)) +                return original.BufferToString.call(this, encoding, start, end); + +            // Otherwise, use our decoding method. +            if (typeof start == 'undefined') start = 0; +            if (typeof end == 'undefined') end = this.length; +            return iconv.decode(this.slice(start, end), encoding); +        } + +        original.BufferWrite = Buffer.prototype.write; +        Buffer.prototype.write = function(string, offset, length, encoding) { +            var _offset = offset, _length = length, _encoding = encoding; +            // Support both (string, offset, length, encoding) +            // and the legacy (string, encoding, offset, length) +            if (isFinite(offset)) { +                if (!isFinite(length)) { +                    encoding = length; +                    length = undefined; +                } +            } else {  // legacy +                var swap = encoding; +                encoding = offset; +                offset = length; +                length = swap; +            } + +            encoding = String(encoding || 'utf8').toLowerCase(); + +            // Use native conversion when possible +            if (Buffer.isNativeEncoding(encoding)) +                return original.BufferWrite.call(this, string, _offset, _length, _encoding); + +            offset = +offset || 0; +            var remaining = this.length - offset; +            if (!length) { +                length = remaining; +            } else { +                length = +length; +                if (length > remaining) { +                    length = remaining; +                } +            } + +            if (string.length > 0 && (length < 0 || offset < 0)) +                throw new RangeError('attempt to write beyond buffer bounds'); + +            // Otherwise, use our encoding method. +            var buf = iconv.encode(string, encoding); +            if (buf.length < length) length = buf.length; +            buf.copy(this, offset, 0, length); +            return length; + +            // TODO: Set _charsWritten. +        } + + +        // -- Readable ------------------------------------------------------------- +        if (iconv.supportsStreams) { +            var Readable = require('stream').Readable; + +            original.ReadableSetEncoding = Readable.prototype.setEncoding; +            Readable.prototype.setEncoding = function setEncoding(enc, options) { +                // Use our own decoder, it has the same interface. +                // We cannot use original function as it doesn't handle BOM-s. +                this._readableState.decoder = iconv.getDecoder(enc, options); +                this._readableState.encoding = enc; +            } + +            Readable.prototype.collect = iconv._collect; +        } +    } + +    // Remove iconv-lite Node primitive extensions. +    iconv.undoExtendNodeEncodings = function undoExtendNodeEncodings() { +        if (!iconv.supportsNodeEncodingsExtension) +            return; +        if (!original) +            throw new Error("require('iconv-lite').undoExtendNodeEncodings(): Nothing to undo; extendNodeEncodings() is not called.") + +        delete Buffer.isNativeEncoding; + +        var SlowBuffer = require('buffer').SlowBuffer; + +        SlowBuffer.prototype.toString = original.SlowBufferToString; +        SlowBuffer.prototype.write = original.SlowBufferWrite; + +        Buffer.isEncoding = original.BufferIsEncoding; +        Buffer.byteLength = original.BufferByteLength; +        Buffer.prototype.toString = original.BufferToString; +        Buffer.prototype.write = original.BufferWrite; + +        if (iconv.supportsStreams) { +            var Readable = require('stream').Readable; + +            Readable.prototype.setEncoding = original.ReadableSetEncoding; +            delete Readable.prototype.collect; +        } + +        original = undefined; +    } +} diff --git a/hash_script/node_modules/iconv-lite/lib/index.d.ts b/hash_script/node_modules/iconv-lite/lib/index.d.ts new file mode 100644 index 0000000..b9c8361 --- /dev/null +++ b/hash_script/node_modules/iconv-lite/lib/index.d.ts @@ -0,0 +1,24 @@ +/*--------------------------------------------------------------------------------------------- + *  Copyright (c) Microsoft Corporation. All rights reserved. + *  Licensed under the MIT License. + *  REQUIREMENT: This definition is dependent on the @types/node definition. + *  Install with `npm install @types/node --save-dev` + *--------------------------------------------------------------------------------------------*/ + +declare module 'iconv-lite' { +	export function decode(buffer: NodeBuffer, encoding: string, options?: Options): string; + +	export function encode(content: string, encoding: string, options?: Options): NodeBuffer; + +	export function encodingExists(encoding: string): boolean; + +	export function decodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream; + +	export function encodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream; +} + +export interface Options { +    stripBOM?: boolean; +    addBOM?: boolean; +    defaultEncoding?: string; +} diff --git a/hash_script/node_modules/iconv-lite/lib/index.js b/hash_script/node_modules/iconv-lite/lib/index.js new file mode 100644 index 0000000..10aced4 --- /dev/null +++ b/hash_script/node_modules/iconv-lite/lib/index.js @@ -0,0 +1,148 @@ +"use strict"; + +// Some environments don't have global Buffer (e.g. React Native). +// Solution would be installing npm modules "buffer" and "stream" explicitly. +var Buffer = require("buffer").Buffer; + +var bomHandling = require("./bom-handling"), +    iconv = module.exports; + +// All codecs and aliases are kept here, keyed by encoding name/alias. +// They are lazy loaded in `iconv.getCodec` from `encodings/index.js`. +iconv.encodings = null; + +// Characters emitted in case of error. +iconv.defaultCharUnicode = '�'; +iconv.defaultCharSingleByte = '?'; + +// Public API. +iconv.encode = function encode(str, encoding, options) { +    str = "" + (str || ""); // Ensure string. + +    var encoder = iconv.getEncoder(encoding, options); + +    var res = encoder.write(str); +    var trail = encoder.end(); +     +    return (trail && trail.length > 0) ? Buffer.concat([res, trail]) : res; +} + +iconv.decode = function decode(buf, encoding, options) { +    if (typeof buf === 'string') { +        if (!iconv.skipDecodeWarning) { +            console.error('Iconv-lite warning: decode()-ing strings is deprecated. Refer to https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding'); +            iconv.skipDecodeWarning = true; +        } + +        buf = new Buffer("" + (buf || ""), "binary"); // Ensure buffer. +    } + +    var decoder = iconv.getDecoder(encoding, options); + +    var res = decoder.write(buf); +    var trail = decoder.end(); + +    return trail ? (res + trail) : res; +} + +iconv.encodingExists = function encodingExists(enc) { +    try { +        iconv.getCodec(enc); +        return true; +    } catch (e) { +        return false; +    } +} + +// Legacy aliases to convert functions +iconv.toEncoding = iconv.encode; +iconv.fromEncoding = iconv.decode; + +// Search for a codec in iconv.encodings. Cache codec data in iconv._codecDataCache. +iconv._codecDataCache = {}; +iconv.getCodec = function getCodec(encoding) { +    if (!iconv.encodings) +        iconv.encodings = require("../encodings"); // Lazy load all encoding definitions. +     +    // Canonicalize encoding name: strip all non-alphanumeric chars and appended year. +    var enc = (''+encoding).toLowerCase().replace(/[^0-9a-z]|:\d{4}$/g, ""); + +    // Traverse iconv.encodings to find actual codec. +    var codecOptions = {}; +    while (true) { +        var codec = iconv._codecDataCache[enc]; +        if (codec) +            return codec; + +        var codecDef = iconv.encodings[enc]; + +        switch (typeof codecDef) { +            case "string": // Direct alias to other encoding. +                enc = codecDef; +                break; + +            case "object": // Alias with options. Can be layered. +                for (var key in codecDef) +                    codecOptions[key] = codecDef[key]; + +                if (!codecOptions.encodingName) +                    codecOptions.encodingName = enc; +                 +                enc = codecDef.type; +                break; + +            case "function": // Codec itself. +                if (!codecOptions.encodingName) +                    codecOptions.encodingName = enc; + +                // The codec function must load all tables and return object with .encoder and .decoder methods. +                // It'll be called only once (for each different options object). +                codec = new codecDef(codecOptions, iconv); + +                iconv._codecDataCache[codecOptions.encodingName] = codec; // Save it to be reused later. +                return codec; + +            default: +                throw new Error("Encoding not recognized: '" + encoding + "' (searched as: '"+enc+"')"); +        } +    } +} + +iconv.getEncoder = function getEncoder(encoding, options) { +    var codec = iconv.getCodec(encoding), +        encoder = new codec.encoder(options, codec); + +    if (codec.bomAware && options && options.addBOM) +        encoder = new bomHandling.PrependBOM(encoder, options); + +    return encoder; +} + +iconv.getDecoder = function getDecoder(encoding, options) { +    var codec = iconv.getCodec(encoding), +        decoder = new codec.decoder(options, codec); + +    if (codec.bomAware && !(options && options.stripBOM === false)) +        decoder = new bomHandling.StripBOM(decoder, options); + +    return decoder; +} + + +// Load extensions in Node. All of them are omitted in Browserify build via 'browser' field in package.json. +var nodeVer = typeof process !== 'undefined' && process.versions && process.versions.node; +if (nodeVer) { + +    // Load streaming support in Node v0.10+ +    var nodeVerArr = nodeVer.split(".").map(Number); +    if (nodeVerArr[0] > 0 || nodeVerArr[1] >= 10) { +        require("./streams")(iconv); +    } + +    // Load Node primitive extensions. +    require("./extend-node")(iconv); +} + +if ("Ā" != "\u0100") { +    console.error("iconv-lite warning: javascript files are loaded not with utf-8 encoding. See https://github.com/ashtuchkin/iconv-lite/wiki/Javascript-source-file-encodings for more info."); +} diff --git a/hash_script/node_modules/iconv-lite/lib/streams.js b/hash_script/node_modules/iconv-lite/lib/streams.js new file mode 100644 index 0000000..4409552 --- /dev/null +++ b/hash_script/node_modules/iconv-lite/lib/streams.js @@ -0,0 +1,121 @@ +"use strict"; + +var Buffer = require("buffer").Buffer, +    Transform = require("stream").Transform; + + +// == Exports ================================================================== +module.exports = function(iconv) { +     +    // Additional Public API. +    iconv.encodeStream = function encodeStream(encoding, options) { +        return new IconvLiteEncoderStream(iconv.getEncoder(encoding, options), options); +    } + +    iconv.decodeStream = function decodeStream(encoding, options) { +        return new IconvLiteDecoderStream(iconv.getDecoder(encoding, options), options); +    } + +    iconv.supportsStreams = true; + + +    // Not published yet. +    iconv.IconvLiteEncoderStream = IconvLiteEncoderStream; +    iconv.IconvLiteDecoderStream = IconvLiteDecoderStream; +    iconv._collect = IconvLiteDecoderStream.prototype.collect; +}; + + +// == Encoder stream ======================================================= +function IconvLiteEncoderStream(conv, options) { +    this.conv = conv; +    options = options || {}; +    options.decodeStrings = false; // We accept only strings, so we don't need to decode them. +    Transform.call(this, options); +} + +IconvLiteEncoderStream.prototype = Object.create(Transform.prototype, { +    constructor: { value: IconvLiteEncoderStream } +}); + +IconvLiteEncoderStream.prototype._transform = function(chunk, encoding, done) { +    if (typeof chunk != 'string') +        return done(new Error("Iconv encoding stream needs strings as its input.")); +    try { +        var res = this.conv.write(chunk); +        if (res && res.length) this.push(res); +        done(); +    } +    catch (e) { +        done(e); +    } +} + +IconvLiteEncoderStream.prototype._flush = function(done) { +    try { +        var res = this.conv.end(); +        if (res && res.length) this.push(res); +        done(); +    } +    catch (e) { +        done(e); +    } +} + +IconvLiteEncoderStream.prototype.collect = function(cb) { +    var chunks = []; +    this.on('error', cb); +    this.on('data', function(chunk) { chunks.push(chunk); }); +    this.on('end', function() { +        cb(null, Buffer.concat(chunks)); +    }); +    return this; +} + + +// == Decoder stream ======================================================= +function IconvLiteDecoderStream(conv, options) { +    this.conv = conv; +    options = options || {}; +    options.encoding = this.encoding = 'utf8'; // We output strings. +    Transform.call(this, options); +} + +IconvLiteDecoderStream.prototype = Object.create(Transform.prototype, { +    constructor: { value: IconvLiteDecoderStream } +}); + +IconvLiteDecoderStream.prototype._transform = function(chunk, encoding, done) { +    if (!Buffer.isBuffer(chunk)) +        return done(new Error("Iconv decoding stream needs buffers as its input.")); +    try { +        var res = this.conv.write(chunk); +        if (res && res.length) this.push(res, this.encoding); +        done(); +    } +    catch (e) { +        done(e); +    } +} + +IconvLiteDecoderStream.prototype._flush = function(done) { +    try { +        var res = this.conv.end(); +        if (res && res.length) this.push(res, this.encoding);                 +        done(); +    } +    catch (e) { +        done(e); +    } +} + +IconvLiteDecoderStream.prototype.collect = function(cb) { +    var res = ''; +    this.on('error', cb); +    this.on('data', function(chunk) { res += chunk; }); +    this.on('end', function() { +        cb(null, res); +    }); +    return this; +} +  | 
