Skip to content

Instantly share code, notes, and snippets.

@shunito
Created September 3, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shunito/cdd17cc7f0f06008d3dd4b03d9f6ac0a to your computer and use it in GitHub Desktop.
Save shunito/cdd17cc7f0f06008d3dd4b03d9f6ac0a to your computer and use it in GitHub Desktop.
BESファイルのUnicode変換試作
// BESファイルのUnicode変換試作(Node版)
// File API使ってブラウザだけで変換できないかなぁ。
// 参考
// brlat様作成の「.bes形式の点字データをUnicode点字のmarkdownファイルに変換」
// https://github.com/brlat/bes-to-markdown
const fs = require('fs');
const path = require('path');
const StringDecoder = require('string_decoder').StringDecoder;
const header_byte = 1029;
const fileName = path.join( __dirname, 'sample', "201806_panf.BES");
const rs = fs.createReadStream(fileName, { start: header_byte });
const dest = fs.createWriteStream('dest.txt', 'utf8');
const decoder = new StringDecoder();
let str = '';
let list = [];
list['a0']=' ';
list['fe']='\r\n';
list['0d']='';
list['a1']='⠁';
list['a3']='⠃';
list['a9']='⠉';
list['b9']='⠙';
list['b1']='⠑';
list['ab']='⠋';
list['bb']='⠛';
list['b3']='⠓';
list['aa']='⠊';
list['ba']='⠚';
list['a5']='⠅';
list['a7']='⠇';
list['ad']='⠍';
list['bd']='⠝';
list['b5']='⠕';
list['af']='⠏';
list['bf']='⠟';
list['b7']='⠗';
list['ae']='⠎';
list['be']='⠞';
list['c5']='⠥';
list['c7']='⠧';
list['cd']='⠭';
list['dd']='⠽';
list['d5']='⠵';
list['cf']='⠯';
list['df']='⠿';
list['d7']='⠷';
list['ce']='⠮';
list['de']='⠾';
list['c1']='⠡';
list['c3']='⠣';
list['c9']='⠩';
list['d9']='⠹';
list['d1']='⠱';
list['cb']='⠫';
list['db']='⠻';
list['d3']='⠳';
list['ca']='⠪';
list['da']='⠺';
list['a2']='⠂';
list['a6']='⠆';
list['b2']='⠒';
list['d2']='⠲';
list['c2']='⠢';
list['b6']='⠖';
list['d6']='⠶';
list['c6']='⠦';
list['b4']='⠔';
list['d4']='⠴';
list['ac']='⠌';
list['cc']='⠬';
list['bc']='⠜';
list['dc']='⠼';
list['a4']='⠄';
list['c4']='⠤';
list['a8']='⠈';
list['b8']='⠘';
list['d8']='⠸';
list['b0']='⠐';
list['c8']='⠨';
list['d0']='⠰';
list['c0']='⠠';
function unpack(bytes) {
let char, chars = [];
for(var i = 0, n = bytes.length; i < n; i++) {
char = bytes[i].toString(16);
if( char.length <2 ){
char = '0'+ char;
}
if( list[char] === undefined ){
console.log( char, list[char] );
}
else{
chars.push( list[char] );
}
}
return chars.join('');
}
rs.on('data', function (data) {
str += unpack( data );
});
rs.on('end', function (data) {
dest.write(str);
dest.end();
//console.log( str );
});
rs.on('error', function (err) {
console.error(err);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment