当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Iconv.convert方法代码示例

本文整理汇总了TypeScript中iconv.Iconv.convert方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Iconv.convert方法的具体用法?TypeScript Iconv.convert怎么用?TypeScript Iconv.convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在iconv.Iconv的用法示例。


在下文中一共展示了Iconv.convert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: cb

 fs.readFile(filename, (err, data) => {
     if (err) {
         cb(err);
         return;
     }
     cb(null, sjisIconv.convert(data).toString());
 });
开发者ID:na2hiro,项目名称:json-kifu-format,代码行数:7,代码来源:fileTest.ts

示例2:

        res.on('end', () => {
            if (!encoding) {
                result.resolve(buffer.toString());
                return;
            }

            var conv = new iconv.Iconv(encoding, 'utf8');
            result.resolve(conv.convert(buffer).toString());
        });
开发者ID:eugene-sea,项目名称:Savings,代码行数:9,代码来源:rates.ts

示例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
 }
开发者ID:OpenParliamentAu,项目名称:law-tools,代码行数:13,代码来源:helpers.ts

示例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;
};
开发者ID:chasidic,项目名称:scraper,代码行数:15,代码来源:bufferToString.ts

示例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);
                        }
                    });
                }
            }

        });
开发者ID:fpoppinga,项目名称:amazon,代码行数:42,代码来源:request.ts

示例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 {
    $: {
        access: string;
开发者ID:swcho,项目名称:busticket,代码行数:30,代码来源:index.ts

示例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});
开发者ID:1drop,项目名称:DefinitelyTyped,代码行数:28,代码来源:iconv-tests.ts


注:本文中的iconv.Iconv.convert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。