當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。