csak-textfile
v0.0.11
Published
Read write text file (unicode,utf8,ansi,etc)
Downloads
16
Maintainers
Readme
csak-textfile
What is csak-textfile?
Its a pure simple javascript text file reader/writer for nodejs (utf8, utf16, etc), but also it works with ansi (example: iso8859-2, etc).
Why need set the codepage?
If the file what you want read it is ANSI, then need convert local codepage characters to Javascript string(utf8)
Install
npm install csak-textfile --save
Examples
The deafult codepage is 28592 (= ISO-8859-2 ), but you can modify it.
Want antoher codepage?
See supported codepage list
Read file (automatic detect utf8 vs ansi)
var TextFile = require('csak-textfile');
///file is utf8 or ansi
var str = TextFile.readFileSyncStr(<filename>);
...
var TextFile = require('csak-textfile').codepage(<codepage>);
///file is utf8 or ansi
var str = TextFile.readFileSyncStr(<filename>);
...
var TextFile = require('csak-textfile');
TextFile.codepage(<codepage>)
///file is utf8 or ansi
var str = TextFile.readFileSyncStr(<filename>);
...
var TextFile = require('csak-textfile');
///file is utf8 or ansi
var str = TextFile.readFileSyncStr(<filename> ,<codepage>);
Write file (ansi)
///use default codepage
TextFile.writeFileSyncStr(<filename>, str);
...
///use special codepage
TextFile.writeFileSyncStr(<filename>, str, <codepage>);
Write file (utf8)
Use nodejs fs module!
var fs = require('fs');
fs.writeFileSync(<filename>, <str>, 'utf-8');