本文整理汇总了TypeScript中iconv.Iconv类的典型用法代码示例。如果您正苦于以下问题:TypeScript Iconv类的具体用法?TypeScript Iconv怎么用?TypeScript Iconv使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Iconv类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: cb
fs.readFile(filename, (err, data) => {
if (err) {
cb(err);
return;
}
const iconv = new Iconv(jschardet.detect(data).encoding, "utf-8");
cb(null, iconv.convert(data).toString());
});
示例2:
res.on('end', () => {
if (!encoding) {
result.resolve(buffer.toString());
return;
}
var conv = new iconv.Iconv(encoding, 'utf8');
result.resolve(conv.convert(buffer).toString());
});
示例3: recode
static recode (file) {
if ( !fs.existsSync(file) ) return null
var Iconv = require('iconv').Iconv
var str = fs.readFileSync(file)
var iconv = new Iconv('ISO-8859-1', 'UTF-8')
var buffer = iconv.convert(str)
var ret = buffer.toString()
ret = ret.replace(/[ÒÓ]/g, '"')
ret = ret.replace(/Õ/g, ' ')
ret = ret.replace(/‑/g, '-')
//ret = ret.replace(/’/g, '\'')
return ret
}
示例4: bufferToString
export function bufferToString(buffer: Buffer | string, isXML: boolean) {
let body = buffer.toString();
let regex = isXML ? CHARSET_REGEX_XML : CHARSET_REGEX_HTML;
let match = body.match(regex);
if (match) {
let CHARSET = match[1].toUpperCase();
if (CHARSET !== 'UTF8' && CHARSET !== 'UTF-8') {
let iconv = new Iconv(CHARSET, 'UTF-8//TRANSLIT//IGNORE');
body = iconv.convert(buffer).toString();
}
}
return body;
};
示例5: callback
request.post('https://' + this.credentials.host + this.endpoint + '?' + queryString, requestOptions, (err, httpResponse, body) => {
if (err)
callback({ origin: 'PostRequest', message: err, metadata: httpResponse });
else {
// Detect non xml content and return without parsing
if (_.has(httpResponse.headers, 'content-type') && httpResponse.headers['content-type'].match(/^text\/plain/)) {
var contentType = httpResponse.headers['content-type'];
contentType = contentType.substr(contentType.indexOf("=") + 1);
if (process.env.NODE_ENV == 'development')
console.log('contentType of response', contentType);
var converter = new Iconv(contentType, 'UTF-8');
var convertedBody = converter.convert(body).toString();
if (_.has(httpResponse.headers, 'content-md5')) {
// Catch md5 mismatch error
var calcResMd5 = this.hexStrToBase64(this.hex_md5(body));
if (calcResMd5 !== httpResponse.headers['content-md5'])
return callback({ origin: 'MD5-Comparison', message: 'MD5-Mismatch', metadata: { 'computedMd5FromResponse': calcResMd5, 'md5FromResponseHeader': httpResponse.headers['content-md5'] } });
// Return raw result
return callback(null, convertedBody);
}
}
else {
// Expect content to be xml (content-type is not specified in every case)
xmlParse(body, { explicitArray: false }, function(err, result) {
if (err) {
// Catch error at XML parsing
callback({ origin: 'XMLParsing', message: err });
} else if (_.has(result, 'ErrorResponse')) {
// Catch error returned from API
callback({ origin: 'MWS', message: result['ErrorResponse']['Error']['Message'], metadata: result['ErrorResponse']['Error'] });
} else {
// Return parsed result
callback(null, result);
}
});
}
}
});
示例6: require
/// <reference path="typings/tsd.d.ts"/>
import fs = require('fs');
import xml2js = require('xml2js');
var Iconv = require('iconv').Iconv;
var euckr2utf8 = new Iconv('EUC-KR', 'UTF-8');
console.log('Hi');
var file = process.argv[2];
console.log(file);
var data = fs.readFileSync(file);
var content = euckr2utf8.convert(data);
interface TArrayType {
$: {
align: string;
id: string;
max: string;
min: string;
size: string;
type: string;
}
}
interface TConstructor {
$: {
示例7: Iconv
///<reference path="./iconv.d.ts" />
import {Iconv} from "iconv";
import {Writable} from "stream";
const iconv: Iconv.Iconv = new Iconv("utf-8", "cp932");
const iconvFromFunction: Iconv.Iconv = Iconv("utf-8", "cp932");
iconv.writable = true;
let buffer: Buffer;
buffer = iconv.convert("hoge");
buffer = iconv.convert("hoge", "utf-8");
buffer = iconv.convert(new Buffer("hoge"), "utf-8");
let result: boolean;
result = iconv.write("hoge");
result = iconv.write("hoge", "utf-8");
result = iconv.write(new Buffer("hoge"), "utf-8");
iconv.end();
iconv.end("hoge");
iconv.end("hoge", "utf-8");
iconv.end(new Buffer("hoge"), "utf-8");
const st: Writable = iconv.pipe(new Writable, {end: true});