How to use the encoding.convert function in encoding

To help you get started, we’ve selected a few encoding examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sozialhelden / accessibility-cloud / legacy-app / converter / converter.js View on Github external
(err, content)=>{
                if (err) {
                    this.logger.error('Could not read static file ' + this.source_description.link);
                    this.emitter.emit('error','No input file');
                } else {
                    try {
                        this.logger.profile("Charset conversion to UTF-8");
                        if (!this.source_description.parameters.charset || this.source_description.parameters.charset === 'auto') {
                            let encoding = detect_encoding(content);
                            this.logger.info('Detected encoding ' + encoding.encoding + ' with a confidence of ' + encoding.confidence + '%.');
                            this.input_data = convert_encoding(content, 'UTF-8', encoding.encoding).utf8Slice();
                        } else {
                            this.input_data = convert_encoding(content, 'UTF-8', this.source_description.parameters.charset).utf8Slice();
                            // OPTIONAL not using ICU encodings and just assume utf8: this.input_data = content.utf8Slice();
                        }
                        this.logger.profile("Charset conversion to UTF-8");
                        this.emitter.emit('provideDataFinish');
                    } catch(err) {
                        this.logger.error('Could not convert encoding for ' + this.source_description.link);
                        this.emitter.emit('error',err);
                    }
                }
            });
    }
github mozilla-b2g / gaia / apps / email / js / ext / pop3 / pop3.js View on Github external
QPStream.prototype.flush = function(){
    var buffer = mimelib.decodeQuotedPrintable(this.current, false, this.charset);

    if(this.charset.toLowerCase() == "binary"){
        // do nothing
    }else if(this.charset.toLowerCase() != "utf-8"){
        buffer = encodinglib.convert(buffer, "utf-8", this.charset);
    }else{
        buffer = new Buffer(buffer, "utf-8");
    }

    this.length += buffer.length;
    this.checksum.update(buffer);
    
    this.emit("data", buffer);
};
github ifgyong / demo / React-native / Helloword / node_modules / node-fetch / lib / body.js View on Github external
res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
    }

    // found charset
    if (res) {
        charset = res.pop();

        // prevent decode issues when sites use incorrect encoding
        // ref: https://hsivonen.fi/encoding-menu/
        if (charset === 'gb2312' || charset === 'gbk') {
            charset = 'gb18030';
        }
    }

    // turn raw buffers into a single utf-8 buffer
    return convert(
        Buffer.concat(this._raw)
        , encoding
        , charset
    );

};
github olymp / olymp / node-fetch / lib / body.js View on Github external
res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
	}

	// found charset
	if (res) {
		charset = res.pop();

		// prevent decode issues when sites use incorrect encoding
		// ref: https://hsivonen.fi/encoding-menu/
		if (charset === 'gb2312' || charset === 'gbk') {
			charset = 'gb18030';
		}
	}

	// turn raw buffers into a single utf-8 buffer
	return convert(
		Buffer.concat(this._raw)
		, encoding
		, charset
	);

};
github LiamKarlMitchell / InfiniteSky / FruitSalad / Grunt / npcToMongo.js View on Github external
function onRecordLoad(record) {
			  	if (record._id) {
			  		record.Name = encoding.convert(record.Name, 'UTF-8', 'EUC-KR').toString();
			  		console.log(record._id, record.Name);
			  		record.Chat1 = encoding.convert(record.Chat1, 'UTF-8', 'EUC-KR').toString();
			  		record.Chat2 = encoding.convert(record.Chat2, 'UTF-8', 'EUC-KR').toString();
			  		record.Chat3 = encoding.convert(record.Chat3, 'UTF-8', 'EUC-KR').toString();
					record.Chat4 = encoding.convert(record.Chat4, 'UTF-8', 'EUC-KR').toString();
			  		record.Chat5 = encoding.convert(record.Chat5, 'UTF-8', 'EUC-KR').toString();
			  		db.NPC.create(record, function(err, doc) {
			  			if (err) {
			  				console.error(err);
			  				return;
			  			}

			  			console.log('Confirming save of '+doc._id);
			  		});
			  	}
			  }
			);
github andris9 / mimelib / lib / mimelib.js View on Github external
decodeBase64: function(str, toCharset, fromCharset) {
        var buffer = new Buffer((str || "").toString(), "base64");
        return convert(buffer, toCharset, fromCharset);
    },
github mozilla-b2g / gaia / apps / email / js / ext / mimelib.js View on Github external
encodeBase64: function(str, toCharset, fromCharset){
        var buffer = convert(str || "", toCharset, fromCharset);
        return addSoftLinebreaks(buffer.toString("base64"), "base64");
    },
github mitica / ascrape-js / lib / index.js View on Github external
request(url, requestOptions, function(err, res, buffer) {
		if (err) {
			return callback(err);
		}

		var contentType = parseContentType(res.headers['content-type']);

		if (contentType.mimeType === 'text/html') {
			contentType.charset = findHTMLCharset(buffer) || contentType.charset;
		}

		contentType.charset = (options.overrideEncoding || contentType.charset || 'utf-8').trim().toLowerCase();

		if (!contentType.charset.match(/^utf-?8$/i)) {
			buffer = encodinglib.convert(buffer, 'UTF-8', contentType.charset);
		}

		buffer = buffer.toString();

		if (options.preprocess) {
			options.preprocess(buffer, res, contentType, function(preprocessErr, data) {
				if (preprocessErr) {
					return callback(preprocessErr);
				}
				callback(null, res, data);
			});
		} else {
			callback(null, res, buffer);
		}
	});
}
github mozilla-b2g / gaia / apps / email / js / ext / mimelib.js View on Github external
decodeMimeWord: function(str, toCharset){
        str = (str || "").toString().trim();

        var fromCharset, encoding, match;

        match = str.match(/^\=\?([\w_\-]+)\?([QB])\?([^\?]+)\?\=$/i);
        if(!match){
            return convert(str, toCharset);
        }

        fromCharset = match[1];
        encoding = (match[2] || "Q").toString().toUpperCase();
        str = (match[3] || "").replace(/_/g, " ");

        if(encoding == "B"){
            return this.decodeBase64(str, toCharset, fromCharset);
        }else if(encoding == "Q"){
            return this.mimeDecode(str, toCharset, fromCharset);    
        }else{
            return str;
        }

        
    },
github roeycohen / Bit-Player-Chrome-Extension / opensubs.js View on Github external
}), i.on("end", function ()
						{
							var e = Buffer.concat(a, s), t = e.toString();
							if ("pol" == n && t.indexOf("�") >= 0)
							{
								var o = encoding.convert(e, "utf8", "cp1250").toString();
								o.indexOf("�") < 0 && (t = o)
							}
							resolve(t)
						}), i.on("error", reject)
					}, i, [s[0].IDSubtitleFile]) : reject({token: i, moviehash: t, subfilename: e})

encoding

Convert encodings, uses iconv-lite

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis

Popular encoding functions