Skip to content

[Android] TypeError in Buffer.concat() #3025

@imkiva

Description

@imkiva

Please excuse my poor English.

I've already ported node-v4.1.1 to my Android device, but I got the following error:

$ node-v4.1.1 trans.js "hello"
buffer.js:238
    buf.copy(buffer, pos);

TypeError: buf.copy is not a function
    at Function.Buffer.concat (buffer.js:238:9)
    at IncomingMessage.<anonymous> (/data/local/trans.js:20:22)
    at emitNone (event.js:72:20)
    at IncomingMessage.emit (event.js:166:7)
    at endReadableNT (_stream_readable.js:893:12)
    at doNTCallback2 (node.js:429:9)
    at process._tickCallback (node.js:343:17)

But there's no problem with v0.12.7

$ node-v0.12.7 trans.js "hello"
您好

Here is the content of trans.js:

var api = 'http://openapi.baidu.com/public/2.0/bmt/translate?client_id=wo99UGjCxweEkgKrKFuf7N0n&from=auto&to=auto&q=';
var http = require("http");
var qs = require("querystring");


function translate(text, callback) {
    var getstr = api + qs.escape(text);

    http.get(getstr, function(res) {
        var buffer = [];
        res.setEncoding('utf-8');

        res.on('data', function(chunk) {
            buffer.push(chunk);
        });

        res.on('end', function() {
            var body = Buffer.concat(buffer).toString();
            var json = JSON.parse(body);

            callback(json);
        });
    });
}


function showResult(json) {
    var res = json.trans_result;

    res.forEach(function(item) {
        console.log(item.dst);
    });
}

if (process.argv.length <= 2) {
    console.log("Usage: translate.js <string-to-translate>");
    process.exit(1);
}

var argv = process.argv.slice(2);
translate(argv[0], showResult);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions