How to use the iconv-lite.fromEncoding function in iconv-lite

To help you get started, we’ve selected a few iconv-lite 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 sosout / modelproxy / lib / proxyfactory.js View on Github external
res.on( 'end', function() {
                    var buffer = bufferHelper.toBuffer();
                    try {
                        var result = self._opt.encoding === ENCODING_RAW 
                            ? buffer
                            : ( self._opt.dataType !== 'json' 
                                ? iconv.fromEncoding( buffer, self._opt.encoding )
                                : JSON.parse( iconv.fromEncoding( buffer, self._opt.encoding ) ) );
                    } catch ( e ) {
                        clearTimeout( timer );
                        errCallback( new Error( "The result has syntax error. " + e ) );
                        return;
                    }
                    clearTimeout( timer );
                    //get data sucessfully
                    
                    //add redis cache
                    var _key = reqObj.proxy._opt.id || ""; 

                    console.log("\033[32mfrom request:"+_key+"\033[0m");

                    reqObj.expire && reqObj.expire>0 && self.addRedisCache(reqObj,result);

                    callback( result, res.headers['set-cookie'] );
github sosout / modelproxy / lib / proxyfactory.js View on Github external
res.on( 'end', function() {
                    var buffer = bufferHelper.toBuffer();
                    try {
                        var result = self._opt.encoding === ENCODING_RAW 
                            ? buffer
                            : ( self._opt.dataType !== 'json' 
                                ? iconv.fromEncoding( buffer, self._opt.encoding )
                                : JSON.parse( iconv.fromEncoding( buffer, self._opt.encoding ) ) );
                    } catch ( e ) {
                        clearTimeout( timer );
                        errCallback( new Error( "The result has syntax error. " + e ) );
                        return;
                    }
                    clearTimeout( timer );
                    //get data sucessfully
                    
                    //add redis cache
                    var _key = reqObj.proxy._opt.id || ""; 

                    console.log("\033[32mfrom request:"+_key+"\033[0m");

                    reqObj.expire && reqObj.expire>0 && self.addRedisCache(reqObj,result);
github kindsoft / kindeditor / build.js View on Github external
function readFileSync(filePath, encoding) {
	var buffer = new Buffer('');

	try {
		buffer = Fs.readFileSync(filePath);
	} catch (e) {
		error(e.toString());
	}

	if (!encoding) {
		return buffer;
	}

	var fileStr = Iconv.fromEncoding(buffer, encoding);

	return fileStr;
}
github sosout / modelproxy / lib / proxyfactory.js View on Github external
res2.on( 'end', function() {
                var buffer = bufferHelper.toBuffer();
                var result;
                try {
                    result = self._opt.encoding === ENCODING_RAW 
                        ? buffer
                        : iconv.fromEncoding( buffer, self._opt.encoding );

                } catch ( e ) {
                    res.statusCode = 500;
                    res.end( e + '' );
                    return;
                }
                res.setHeader( 'Set-Cookie', res2.headers['set-cookie'] );
                res.setHeader( 'Content-Type'
                    , ( self._opt.dataType === 'json' ? 'application/json' : 'text/html' )
                        + ';charset=UTF-8' );
                res.end( result );
            } );
        } );
github smartcloudpro / ali-data-proxy-lite / lib / plugins / http.js View on Github external
var buffer = Buffer.concat(source, size);
            if (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 202) {
                var e = new Error('Response error. rid = ' + rid
                + ', interfaceId = ' + self._opt.id
                + ', url = ' + self._opt.currUrl
                + ', statusCode = ' + res.statusCode);
                e.statusCode = res.statusCode;
                e.responseText = buffer.toString();
                ( isCompleted = true ) && errCallback(e);
                return;
            }
            try {
                var result = self._opt.encoding === Constant.ENCODING_RAW
                    ? buffer
                    : ( self._opt.dataType !== Constant.JSON && self._opt.dataType !== Constant.JSONP
                    ? iconv.fromEncoding(buffer, self._opt.encoding)
                    : JSON.parse(iconv.fromEncoding(buffer, self._opt.encoding)) );
            } catch (e) {
                errCallback(new Error('The result has syntax error. interfaceId = '
                + self._opt.id + ', url = ' + self._opt.currUrl + '. Caused By: ' + e.message));
                return;
            }

            isCompleted || callback(result, res.headers['set-cookie']);
            isCompleted = true;
        });
github smartcloudpro / ali-data-proxy-lite / lib / plugins / http.js View on Github external
if (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 202) {
                var e = new Error('Response error. rid = ' + rid
                + ', interfaceId = ' + self._opt.id
                + ', url = ' + self._opt.currUrl
                + ', statusCode = ' + res.statusCode);
                e.statusCode = res.statusCode;
                e.responseText = buffer.toString();
                ( isCompleted = true ) && errCallback(e);
                return;
            }
            try {
                var result = self._opt.encoding === Constant.ENCODING_RAW
                    ? buffer
                    : ( self._opt.dataType !== Constant.JSON && self._opt.dataType !== Constant.JSONP
                    ? iconv.fromEncoding(buffer, self._opt.encoding)
                    : JSON.parse(iconv.fromEncoding(buffer, self._opt.encoding)) );
            } catch (e) {
                errCallback(new Error('The result has syntax error. interfaceId = '
                + self._opt.id + ', url = ' + self._opt.currUrl + '. Caused By: ' + e.message));
                return;
            }

            isCompleted || callback(result, res.headers['set-cookie']);
            isCompleted = true;
        });
github smartcloudpro / ali-data-proxy-lite / lib / plugins / http.js View on Github external
res2.on('end', function () {
            var buffer = Buffer.concat(source, size);
            var result;
            try {
                result = self._opt.encoding === Constant.ENCODING_RAW
                    ? buffer
                    : iconv.fromEncoding(buffer, self._opt.encoding);
            } catch (e) {
                res.statusCode = 500;
                res.end(e + '');
                return;
            }
            res.setHeader('Set-Cookie', res2.headers['set-cookie']);
            res.statusCode = res2.statusCode;
            res.setHeader('Content-Type', res2.headers['Content-Type']);
            res.end(result);
        });
        res2.on('error', function (err) {