/**
 * Created by Tony on 2017/3/27.
 */
var fs = require('fs');
fs.readFile('../../tmp_data/test_bills_data2.js',function(err,data){
    if(err) throw err;

    var jsonObj = JSON.parse(data);
    var space = ' ';
    var newLine = '\n';
    var chunks = [];
    var length = 0;

    for(var i=0,size=jsonObj.length;i<size;i++){
        var one = jsonObj[i];
        //what value you want
        var value1 = one['ID'];
        var value2 = one['FullCode'];
        var value3 = one['Name'];
        var value = value1 + space + value2 + space + value3 + space + newLine;
        var buffer = new Buffer(value);
        chunks.push(buffer);
        length += buffer.length;
    }

    var resultBuffer = new Buffer(length);
    for(var i=0,size=chunks.length,pos=0;i<size;i++){
        chunks[i].copy(resultBuffer,pos);
        pos += chunks[i].length;
    }

    fs.writeFile('../../../tmp/结果.text',resultBuffer,function(err){
        if(err) throw err;
        console.log('has finished');
    });

});