mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
add encoding support to file in/out node (#2066)
* add encoding support to file in/out node * update package.json * change default encoding label: 'none' -> 'utf8[default]' * add a missing message catalogue entry * change default encoding label
This commit is contained in:
parent
3c013b3533
commit
dc89218702
@ -69,8 +69,9 @@
|
|||||||
"semver": "5.6.0",
|
"semver": "5.6.0",
|
||||||
"uglify-js": "3.4.9",
|
"uglify-js": "3.4.9",
|
||||||
"when": "3.7.8",
|
"when": "3.7.8",
|
||||||
"ws": "6.1.4",
|
"ws": "6.1.3",
|
||||||
"xml2js": "0.4.19"
|
"xml2js": "0.4.19",
|
||||||
|
"iconv-lite": "0.4.24"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"bcrypt": "~2.0.0"
|
"bcrypt": "~2.0.0"
|
||||||
|
@ -22,6 +22,11 @@
|
|||||||
<input type="checkbox" id="node-input-createDir" style="display: inline-block; width: auto; vertical-align: top;">
|
<input type="checkbox" id="node-input-createDir" style="display: inline-block; width: auto; vertical-align: top;">
|
||||||
<label for="node-input-createDir" style="width: 70%;"><span data-i18n="file.label.createdir"></span></label>
|
<label for="node-input-createDir" style="width: 70%;"><span data-i18n="file.label.createdir"></span></label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-encoding"><i class="fa fa-flag"></i> <span data-i18n="file.label.encoding"></span></label>
|
||||||
|
<select type="text" id="node-input-encoding" style="width: 250px;">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
@ -48,6 +53,11 @@
|
|||||||
<input type="checkbox" id="node-input-sendError" style="width:auto">
|
<input type="checkbox" id="node-input-sendError" style="width:auto">
|
||||||
<label style="width:auto; margin-bottom:0; vertical-align: middle;" for="node-input-sendError" data-i18n="file.label.sendError"></label>
|
<label style="width:auto; margin-bottom:0; vertical-align: middle;" for="node-input-sendError" data-i18n="file.label.sendError"></label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row" id="encoding-spec">
|
||||||
|
<label for="node-input-encoding"><i class="fa fa-flag"></i> <span data-i18n="file.label.encoding"></span></label>
|
||||||
|
<select type="text" id="node-input-encoding" style="width: 250px;">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
@ -56,6 +66,132 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
(function(){
|
||||||
|
var encodings = [
|
||||||
|
[ "file.encoding.native",
|
||||||
|
"utf8",
|
||||||
|
"ucs2",
|
||||||
|
"utf-16le",
|
||||||
|
"ascii",
|
||||||
|
"binary",
|
||||||
|
"base64",
|
||||||
|
"hex"
|
||||||
|
],
|
||||||
|
[ "file.encoding.unicode",
|
||||||
|
"utf-16be",
|
||||||
|
],
|
||||||
|
[ "file.encoding.japanese",
|
||||||
|
"Shift_JIS",
|
||||||
|
"Windows-31j",
|
||||||
|
"Windows932",
|
||||||
|
"EUC-JP"
|
||||||
|
],
|
||||||
|
[ "file.encoding.chinese",
|
||||||
|
"GB2312",
|
||||||
|
"GBK",
|
||||||
|
"GB18030",
|
||||||
|
"Windows936",
|
||||||
|
"EUC-CN"
|
||||||
|
],
|
||||||
|
[ "file.encoding.korean",
|
||||||
|
"KS_C_5601",
|
||||||
|
"Windows949",
|
||||||
|
"EUC-KR"
|
||||||
|
],
|
||||||
|
[ "file.encoding.taiwan",
|
||||||
|
"Big5",
|
||||||
|
"Big5-HKSCS",
|
||||||
|
"Windows950"
|
||||||
|
],
|
||||||
|
[ "file.encoding.windows",
|
||||||
|
"cp874",
|
||||||
|
"cp1250",
|
||||||
|
"cp1251",
|
||||||
|
"cp1252",
|
||||||
|
"cp1253",
|
||||||
|
"cp1254",
|
||||||
|
"cp1255",
|
||||||
|
"cp1256",
|
||||||
|
"cp1257",
|
||||||
|
"cp1258"
|
||||||
|
],
|
||||||
|
[ "file.encoding.iso",
|
||||||
|
"ISO-8859-1",
|
||||||
|
"ISO-8859-2",
|
||||||
|
"ISO-8859-3",
|
||||||
|
"ISO-8859-4",
|
||||||
|
"ISO-8859-5",
|
||||||
|
"ISO-8859-6",
|
||||||
|
"ISO-8859-7",
|
||||||
|
"ISO-8859-8",
|
||||||
|
"ISO-8859-9",
|
||||||
|
"ISO-8859-10",
|
||||||
|
"ISO-8859-11",
|
||||||
|
"ISO-8859-12",
|
||||||
|
"ISO-8859-13",
|
||||||
|
"ISO-8859-14",
|
||||||
|
"ISO-8859-15",
|
||||||
|
"ISO-8859-16"
|
||||||
|
],
|
||||||
|
[ "file.encoding.ibm",
|
||||||
|
"cp437",
|
||||||
|
"cp737",
|
||||||
|
"cp775",
|
||||||
|
"cp808",
|
||||||
|
"cp850",
|
||||||
|
"cp852",
|
||||||
|
"cp855",
|
||||||
|
"cp856",
|
||||||
|
"cp857",
|
||||||
|
"cp858",
|
||||||
|
"cp860",
|
||||||
|
"cp861",
|
||||||
|
"cp866",
|
||||||
|
"cp869",
|
||||||
|
"cp922",
|
||||||
|
"cp1046",
|
||||||
|
"cp1124",
|
||||||
|
"cp1125",
|
||||||
|
"cp1129",
|
||||||
|
"cp1133",
|
||||||
|
"cp1161",
|
||||||
|
"cp1162",
|
||||||
|
"cp1163"
|
||||||
|
],
|
||||||
|
[ "file.encoding.mac",
|
||||||
|
"maccroatian",
|
||||||
|
"maccyrillic",
|
||||||
|
"macgreek",
|
||||||
|
"maciceland",
|
||||||
|
"macroman",
|
||||||
|
"macromania",
|
||||||
|
"macthai",
|
||||||
|
"macturkish",
|
||||||
|
"macukraine",
|
||||||
|
"maccenteuro",
|
||||||
|
"macintosh"
|
||||||
|
],
|
||||||
|
[ "file.encoding.koi8",
|
||||||
|
"koi8-r",
|
||||||
|
"koi8-u",
|
||||||
|
"koi8-ru",
|
||||||
|
"koi8-t"
|
||||||
|
],
|
||||||
|
[ "file.encoding.misc",
|
||||||
|
"armscii8",
|
||||||
|
"rk1048",
|
||||||
|
"tcvn",
|
||||||
|
"georgianacademy",
|
||||||
|
"georgianps",
|
||||||
|
"pt154",
|
||||||
|
"viscii",
|
||||||
|
"iso646cn",
|
||||||
|
"iso646jp",
|
||||||
|
"hproman8",
|
||||||
|
"tis620"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
RED.nodes.registerType('file',{
|
RED.nodes.registerType('file',{
|
||||||
category: 'storage-output',
|
category: 'storage-output',
|
||||||
defaults: {
|
defaults: {
|
||||||
@ -63,7 +199,8 @@
|
|||||||
filename: {value:""},
|
filename: {value:""},
|
||||||
appendNewline: {value:true},
|
appendNewline: {value:true},
|
||||||
createDir: {value:false},
|
createDir: {value:false},
|
||||||
overwriteFile: {value:"false"}
|
overwriteFile: {value:"false"},
|
||||||
|
encoding: {value:"none"}
|
||||||
},
|
},
|
||||||
color:"BurlyWood",
|
color:"BurlyWood",
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -80,6 +217,33 @@
|
|||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
|
var node = this;
|
||||||
|
var encSel = $("#node-input-encoding");
|
||||||
|
$("<option/>", {
|
||||||
|
value: "none",
|
||||||
|
label: node._("file.encoding.none")
|
||||||
|
}).appendTo(encSel);
|
||||||
|
encodings.forEach(function(item) {
|
||||||
|
if(Array.isArray(item)) {
|
||||||
|
var group = $("<optgroup/>", {
|
||||||
|
label: node._(item[0])
|
||||||
|
}).appendTo(encSel);
|
||||||
|
for (var i = 1; i < item.length; i++) {
|
||||||
|
var enc = item[i];
|
||||||
|
$("<option/>", {
|
||||||
|
value: enc,
|
||||||
|
label: enc
|
||||||
|
}).appendTo(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("<option/>", {
|
||||||
|
value: item,
|
||||||
|
label: item
|
||||||
|
}).appendTo(encSel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
encSel.val(node.encoding);
|
||||||
$("#node-input-overwriteFile").on("change",function() {
|
$("#node-input-overwriteFile").on("change",function() {
|
||||||
if (this.value === "delete") { $(".form-row-file-write-options").hide(); }
|
if (this.value === "delete") { $(".form-row-file-write-options").hide(); }
|
||||||
else { $(".form-row-file-write-options").show(); }
|
else { $(".form-row-file-write-options").show(); }
|
||||||
@ -94,7 +258,8 @@
|
|||||||
filename: {value:""},
|
filename: {value:""},
|
||||||
format: {value:"utf8"},
|
format: {value:"utf8"},
|
||||||
chunk: {value:false},
|
chunk: {value:false},
|
||||||
sendError: {value: false}
|
sendError: {value: false},
|
||||||
|
encoding: {value: "none"}
|
||||||
},
|
},
|
||||||
color:"BurlyWood",
|
color:"BurlyWood",
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -110,19 +275,46 @@
|
|||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
|
var node = this;
|
||||||
|
var encSel = $("#node-input-encoding");
|
||||||
|
$("<option/>", {
|
||||||
|
value: "none",
|
||||||
|
label: node._("file.encoding.none")
|
||||||
|
}).appendTo(encSel);
|
||||||
|
encodings.forEach(function(item) {
|
||||||
|
if(Array.isArray(item)) {
|
||||||
|
var group = $("<optgroup/>", {
|
||||||
|
label: node._(item[0])
|
||||||
|
}).appendTo(encSel);
|
||||||
|
for (var i = 1; i < item.length; i++) {
|
||||||
|
var enc = item[i];
|
||||||
|
$("<option/>", {
|
||||||
|
value: enc,
|
||||||
|
label: enc
|
||||||
|
}).appendTo(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("<option/>", {
|
||||||
|
value: item,
|
||||||
|
label: item
|
||||||
|
}).appendTo(encSel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
encSel.val(node.encoding);
|
||||||
if (this.sendError === undefined) {
|
if (this.sendError === undefined) {
|
||||||
$("#node-input-sendError").prop("checked",true);
|
$("#node-input-sendError").prop("checked",true);
|
||||||
}
|
}
|
||||||
$("#node-input-format").on("change",function() {
|
$("#node-input-format").on("change",function() {
|
||||||
if ($("#node-input-format").val() === "utf8") {
|
var format = $("#node-input-format").val();
|
||||||
$("#buffer-input-type").hide();
|
if ((format === "utf8") || (format === "lines")) {
|
||||||
$("#line-input-type").show();
|
$("#encoding-spec").show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$("#buffer-input-type").show();
|
$("#encoding-spec").hide();
|
||||||
$("#line-input-type").hide();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
@ -19,13 +19,29 @@ module.exports = function(RED) {
|
|||||||
var fs = require("fs-extra");
|
var fs = require("fs-extra");
|
||||||
var os = require("os");
|
var os = require("os");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
var iconv = require("iconv-lite")
|
||||||
|
|
||||||
|
function encode(data, enc) {
|
||||||
|
if (enc !== "none") {
|
||||||
|
return iconv.encode(data, enc);
|
||||||
|
}
|
||||||
|
return Buffer.from(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decode(data, enc) {
|
||||||
|
if (enc !== "none") {
|
||||||
|
return iconv.decode(data, enc);
|
||||||
|
}
|
||||||
|
return data.toString();
|
||||||
|
}
|
||||||
|
|
||||||
function FileNode(n) {
|
function FileNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.filename = n.filename;
|
this.filename = n.filename;
|
||||||
this.appendNewline = n.appendNewline;
|
this.appendNewline = n.appendNewline;
|
||||||
this.overwriteFile = n.overwriteFile.toString();
|
this.overwriteFile = n.overwriteFile.toString();
|
||||||
this.createDir = n.createDir || false;
|
this.createDir = n.createDir || false;
|
||||||
|
this.encoding = n.encoding || "none";
|
||||||
var node = this;
|
var node = this;
|
||||||
node.wstream = null;
|
node.wstream = null;
|
||||||
node.msgQueue = [];
|
node.msgQueue = [];
|
||||||
@ -75,7 +91,7 @@ module.exports = function(RED) {
|
|||||||
if (typeof data === "boolean") { data = data.toString(); }
|
if (typeof data === "boolean") { data = data.toString(); }
|
||||||
if (typeof data === "number") { data = data.toString(); }
|
if (typeof data === "number") { data = data.toString(); }
|
||||||
if ((node.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
|
if ((node.appendNewline) && (!Buffer.isBuffer(data))) { data += os.EOL; }
|
||||||
var buf = Buffer.from(data);
|
var buf = encode(data, node.encoding);
|
||||||
if (node.overwriteFile === "true") {
|
if (node.overwriteFile === "true") {
|
||||||
var wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true });
|
var wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true });
|
||||||
node.wstream = wstream;
|
node.wstream = wstream;
|
||||||
@ -222,6 +238,7 @@ module.exports = function(RED) {
|
|||||||
this.filename = n.filename;
|
this.filename = n.filename;
|
||||||
this.format = n.format;
|
this.format = n.format;
|
||||||
this.chunk = false;
|
this.chunk = false;
|
||||||
|
this.encoding = n.encoding || "none";
|
||||||
if (n.sendError === undefined) {
|
if (n.sendError === undefined) {
|
||||||
this.sendError = true;
|
this.sendError = true;
|
||||||
} else {
|
} else {
|
||||||
@ -261,7 +278,7 @@ module.exports = function(RED) {
|
|||||||
if (node.chunk === true) {
|
if (node.chunk === true) {
|
||||||
getout = true;
|
getout = true;
|
||||||
if (node.format === "lines") {
|
if (node.format === "lines") {
|
||||||
spare += chunk.toString();
|
spare += decode(chunk, node.encoding);
|
||||||
var bits = spare.split("\n");
|
var bits = spare.split("\n");
|
||||||
for (var i=0; i < bits.length - 1; i++) {
|
for (var i=0; i < bits.length - 1; i++) {
|
||||||
var m = {
|
var m = {
|
||||||
@ -306,7 +323,9 @@ module.exports = function(RED) {
|
|||||||
})
|
})
|
||||||
.on('end', function() {
|
.on('end', function() {
|
||||||
if (node.chunk === false) {
|
if (node.chunk === false) {
|
||||||
if (node.format === "utf8") { msg.payload = lines.toString(); }
|
if (node.format === "utf8") {
|
||||||
|
msg.payload = decode(lines, node.encoding);
|
||||||
|
}
|
||||||
else { msg.payload = lines; }
|
else { msg.payload = lines; }
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
|
@ -860,6 +860,7 @@
|
|||||||
"filelabel": "file",
|
"filelabel": "file",
|
||||||
"sendError": "Send message on error (legacy mode)",
|
"sendError": "Send message on error (legacy mode)",
|
||||||
"deletelabel": "delete __file__",
|
"deletelabel": "delete __file__",
|
||||||
|
"encoding": "Encoding"
|
||||||
"utf8String": "UTF8 string",
|
"utf8String": "UTF8 string",
|
||||||
"binaryBuffer": "binary buffer"
|
"binaryBuffer": "binary buffer"
|
||||||
},
|
},
|
||||||
@ -879,6 +880,21 @@
|
|||||||
"deletedfile": "deleted file: __file__",
|
"deletedfile": "deleted file: __file__",
|
||||||
"appendedfile": "appended to file: __file__"
|
"appendedfile": "appended to file: __file__"
|
||||||
},
|
},
|
||||||
|
"encoding": {
|
||||||
|
"none": "default",
|
||||||
|
"native": "Native",
|
||||||
|
"unicode": "Unicode",
|
||||||
|
"japanese": "Japanese",
|
||||||
|
"chinese": "Chinese",
|
||||||
|
"korean": "Korean",
|
||||||
|
"taiwan": "Taiwan/Hong Kong",
|
||||||
|
"windows": "Windows codepages",
|
||||||
|
"iso": "ISO codepages",
|
||||||
|
"ibm": "IBM codepages",
|
||||||
|
"mac": "Mac codepages",
|
||||||
|
"koi8": "KOI8 codepages",
|
||||||
|
"misc": "Miscellaneous"
|
||||||
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"nofilename": "No filename specified",
|
"nofilename": "No filename specified",
|
||||||
"invaliddelete": "Warning: Invalid delete. Please use specific delete option in config dialog.",
|
"invaliddelete": "Warning: Invalid delete. Please use specific delete option in config dialog.",
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
<p>It can be configured to overwrite the entire file rather than append. For example,
|
<p>It can be configured to overwrite the entire file rather than append. For example,
|
||||||
when writing binary data to a file, such as an image, this option should be used
|
when writing binary data to a file, such as an image, this option should be used
|
||||||
and the option to append a newline should be disabled.</p>
|
and the option to append a newline should be disabled.</p>
|
||||||
|
<p>Encoding of data written to a file can be specified from list of encodings.</p>
|
||||||
<p>Alternatively, this node can be configured to delete the file.</p>
|
<p>Alternatively, this node can be configured to delete the file.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -63,6 +64,7 @@
|
|||||||
split into smaller buffer chunks - the chunk size being operating system dependant, but typically 64k (Linux/Mac) or 41k (Windows).</p>
|
split into smaller buffer chunks - the chunk size being operating system dependant, but typically 64k (Linux/Mac) or 41k (Windows).</p>
|
||||||
<p>When split into multiple messages, each message will have a <code>parts</code>
|
<p>When split into multiple messages, each message will have a <code>parts</code>
|
||||||
property set, forming a complete message sequence.</p>
|
property set, forming a complete message sequence.</p>
|
||||||
|
<p>Encoding of input data can be specified from list of encodings if output format is string.</p>
|
||||||
<h4>Legacy error handling</h4>
|
<h4>Legacy error handling</h4>
|
||||||
<p>Before Node-RED 0.17, if this node hit an error whilst reading the file, it would
|
<p>Before Node-RED 0.17, if this node hit an error whilst reading the file, it would
|
||||||
send a message with no <code>msg.payload</code> and <code>msg.error</code> set to the
|
send a message with no <code>msg.payload</code> and <code>msg.error</code> set to the
|
||||||
|
@ -858,6 +858,7 @@
|
|||||||
"filelabel": "file",
|
"filelabel": "file",
|
||||||
"sendError": "エラーメッセージを送信(互換モード)",
|
"sendError": "エラーメッセージを送信(互換モード)",
|
||||||
"deletelabel": "delete __file__",
|
"deletelabel": "delete __file__",
|
||||||
|
"encoding": "エンコーディング"
|
||||||
"utf8String": "UTF8文字列",
|
"utf8String": "UTF8文字列",
|
||||||
"binaryBuffer": "バイナリバッファ"
|
"binaryBuffer": "バイナリバッファ"
|
||||||
},
|
},
|
||||||
@ -877,6 +878,21 @@
|
|||||||
"deletedfile": "ファイルを削除しました: __file__",
|
"deletedfile": "ファイルを削除しました: __file__",
|
||||||
"appendedfile": "ファイルへ追記しました: __file__"
|
"appendedfile": "ファイルへ追記しました: __file__"
|
||||||
},
|
},
|
||||||
|
"encoding": {
|
||||||
|
"none": "デフォルト",
|
||||||
|
"native": "ネイティブ",
|
||||||
|
"unicode": "UNICODE",
|
||||||
|
"japanese": "日本",
|
||||||
|
"chinese": "中国",
|
||||||
|
"korean": "韓国",
|
||||||
|
"taiwan": "台湾/香港",
|
||||||
|
"windows": "Windowsコードページ",
|
||||||
|
"iso": "ISOコードページ",
|
||||||
|
"ibm": "IBMコードページ",
|
||||||
|
"mac": "Macコードページ",
|
||||||
|
"koi8": "KOI8コードページ",
|
||||||
|
"misc": "その他"
|
||||||
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"nofilename": "ファイル名が設定されていません",
|
"nofilename": "ファイル名が設定されていません",
|
||||||
"invaliddelete": "警告: 削除が無効です。設定ダイアログで特定の削除設定を使用してください",
|
"invaliddelete": "警告: 削除が無効です。設定ダイアログで特定の削除設定を使用してください",
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
<p>入力メッセージのペイロードをファイルの最後に追記します。改行(\n)を各データの最後に追加することもできます。</p>
|
<p>入力メッセージのペイロードをファイルの最後に追記します。改行(\n)を各データの最後に追加することもできます。</p>
|
||||||
<p><code>msg.filename</code>を使う場合、書き込みを行う毎にファイルをクローズします。より良い性能を得るためにはファイル名をノードに設定してください。</p>
|
<p><code>msg.filename</code>を使う場合、書き込みを行う毎にファイルをクローズします。より良い性能を得るためにはファイル名をノードに設定してください。</p>
|
||||||
<p>追記を行う代わりに、ファイル全体を上書きするように設定することもできます。例えば、画像のようなバイナリデータをファイルに書き出す場合は、このオプションを指定し、改行を追記するオプションを指定しないようにします。</p>
|
<p>追記を行う代わりに、ファイル全体を上書きするように設定することもできます。例えば、画像のようなバイナリデータをファイルに書き出す場合は、このオプションを指定し、改行を追記するオプションを指定しないようにします。</p>
|
||||||
|
<p>ファイル出力の際のエンコーディングは、エンコーディングリストから選択できます。</p>
|
||||||
<p>この他、ファイルの削除を行うことも可能です。</p>
|
<p>この他、ファイルの削除を行うことも可能です。</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -51,6 +52,7 @@
|
|||||||
<p>Windowsではパスの区切り文字を(例えば、<code>\\ユーザー\\名前</code>のように)エスケープする必要があります。</p>
|
<p>Windowsではパスの区切り文字を(例えば、<code>\\ユーザー\\名前</code>のように)エスケープする必要があります。</p>
|
||||||
<p>テキストファイルの場合、行毎に分割して各々メッセージを送信することができます。また、バイナリファイルの場合、小さな塊のバッファに分割して送信できます。バッファの分割単位はオペレーティングシステム依存ですが、一般に64k(Linux/Mac)もしくは41k(Windows)です。</p>
|
<p>テキストファイルの場合、行毎に分割して各々メッセージを送信することができます。また、バイナリファイルの場合、小さな塊のバッファに分割して送信できます。バッファの分割単位はオペレーティングシステム依存ですが、一般に64k(Linux/Mac)もしくは41k(Windows)です。</p>
|
||||||
<p>複数のメッセージに分割する場合、各メッセージには<code>parts</code>プロパティが設定され、メッセージ列を構成します。</p>
|
<p>複数のメッセージに分割する場合、各メッセージには<code>parts</code>プロパティが設定され、メッセージ列を構成します。</p>
|
||||||
|
<p>主力形式が文字列の場合、入力データのエンコーディングをエンコーディングリストから選択できます。</p>
|
||||||
<h4>旧式のエラー処理</h4>
|
<h4>旧式のエラー処理</h4>
|
||||||
<p>Node-RED 0.17より前の版では、ファイルの読み込み時にエラーが発生すると<code>payload</code>を持たず<code>error</code>プロパティにエラーの詳細情報を設定したメッセージを送信します。この動作モードは非推奨であり、新しいノード実装ではデフォルトでは無効としています。ノードの設定により、必要に応じてこのモードを有効にできます。</p>
|
<p>Node-RED 0.17より前の版では、ファイルの読み込み時にエラーが発生すると<code>payload</code>を持たず<code>error</code>プロパティにエラーの詳細情報を設定したメッセージを送信します。この動作モードは非推奨であり、新しいノード実装ではデフォルトでは無効としています。ノードの設定により、必要に応じてこのモードを有効にできます。</p>
|
||||||
<p>エラーはcatchノードで補足して処理することを推奨します。</p>
|
<p>エラーはcatchノードで補足して処理することを推奨します。</p>
|
||||||
|
@ -36,7 +36,8 @@
|
|||||||
"on-headers": "1.0.2",
|
"on-headers": "1.0.2",
|
||||||
"raw-body": "2.3.3",
|
"raw-body": "2.3.3",
|
||||||
"request": "2.88.0",
|
"request": "2.88.0",
|
||||||
"ws": "6.1.4",
|
"ws": "6.1.3",
|
||||||
"xml2js": "0.4.19"
|
"xml2js": "0.4.19",
|
||||||
|
"iconv-lite": "0.4.24"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,26 @@ var path = require('path');
|
|||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
|
var iconv = require("iconv-lite");
|
||||||
var fileNode = require("nr-test-utils").require("@node-red/nodes/core/storage/50-file.js");
|
var fileNode = require("nr-test-utils").require("@node-red/nodes/core/storage/50-file.js");
|
||||||
var helper = require("node-red-node-test-helper");
|
var helper = require("node-red-node-test-helper");
|
||||||
|
|
||||||
describe('file Nodes', function() {
|
describe('file Nodes', function() {
|
||||||
|
|
||||||
|
function encode(s, enc) {
|
||||||
|
if (enc === "none") {
|
||||||
|
return Buffer.from(s);
|
||||||
|
}
|
||||||
|
return iconv.encode(s, enc);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decode(data, enc) {
|
||||||
|
if (enc === "none") {
|
||||||
|
return data.toString();
|
||||||
|
}
|
||||||
|
return iconv.decode(data, enc);
|
||||||
|
}
|
||||||
|
|
||||||
describe('file out Node', function() {
|
describe('file out Node', function() {
|
||||||
|
|
||||||
var resourcesDir = path.join(__dirname,"..","..","..","resources");
|
var resourcesDir = path.join(__dirname,"..","..","..","resources");
|
||||||
@ -650,6 +665,372 @@ describe('file Nodes', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('encodings', function() {
|
||||||
|
|
||||||
|
function checkWriteWithEncoding(enc, data, done) {
|
||||||
|
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":true, encoding:enc, wires: [["helperNode1"]]},
|
||||||
|
{id:"helperNode1", type:"helper"}];
|
||||||
|
helper.load(fileNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("fileNode1");
|
||||||
|
var n2 = helper.getNode("helperNode1");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
try {
|
||||||
|
var f = fs.readFileSync(fileToTest);
|
||||||
|
f.equals(encode(data, enc)).should.be.true();
|
||||||
|
fs.unlinkSync(fileToTest);
|
||||||
|
msg.should.have.property("payload", data);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({payload:data});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// default
|
||||||
|
it('should write to a file with "none" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("none", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Native
|
||||||
|
it('should write to a file with "utf8" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("utf8", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "ucs2" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("ucs2", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "utf-16le" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("utf-16le", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "binary" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("binary", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "base64" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("base64", "5pel5pys6KqeCg==", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "hex" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("hex", "deadbeef", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Unicode
|
||||||
|
it('should write to a file with "utf-16be" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("utf-16be", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Japanese
|
||||||
|
it('should write to a file with "Shift_JIS" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Shift_JIS", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "Windows-31j" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Windows-31j", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "Windows932" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Windows932", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "EUC-JP" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("EUC-JP", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// following encoding tests should be more specific
|
||||||
|
// Chinese
|
||||||
|
it('should write to a file with "GB2312" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("GB2312", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "GBK" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("GBK", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "GB18030" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("GB18030", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "Windows936" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Windows936", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "EUC-CN" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("EUC-CN", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Korean
|
||||||
|
it('should write to a file with "KS_C_5601" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("KS_C_5601", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "Windows949" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Windows949", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "EUC-KR" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("EUC-KR", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Taiwan/Hong Kong
|
||||||
|
it('should write to a file with "Big5" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Big5", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "Big5-HKSCS" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Big5-HKSCS", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "Windows950" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("Windows950", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Windows
|
||||||
|
it('should write to a file with "cp874" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp874", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1250" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1250", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1251" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1251", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1252" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1252", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1253" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1253", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1254" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1254", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1255" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1255", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1256" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1256", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1257" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1257", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1258" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1258", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// IBM
|
||||||
|
it('should write to a file with "cp437" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp437", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp737" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp737", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp775" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp775", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp808" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp808", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp850" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp850", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp852" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp852", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp855" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp855", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp856" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp856", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp857" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp857", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp858" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp858", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp860" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp860", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp861" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp861", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp866" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp866", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp869" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp869", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp922" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp922", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1046" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1046", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1124" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1124", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1125" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1125", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1129" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1129", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1133" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1133", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1161" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1161", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1162" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1162", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "cp1163" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("cp1163", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mac
|
||||||
|
it('should write to a file with "maccroatian" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("maccroatian", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "maccyrillic" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("maccyrillic", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "macgreek" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("macgreek", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "maciceland" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("maciceland", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "macroman" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("macroman", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "macromania" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("macromania", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "macthai" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("macthai", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "macturkish" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("macturkish", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "macukraine" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("macukraine", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "maccenteuro" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("maccenteuro", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "macintosh" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("macintosh", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// KOI8
|
||||||
|
it('should write to a file with "koi8-r" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("koi8-r", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "koi8-u" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("koi8-u", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "koi8-ru" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("koi8-ru", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "koi8-t" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("koi8-t", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
it('should write to a file with "armscii8" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("armscii8", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "rk1048" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("rk1048", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "tcvn" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("tcvn", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "georgianacademy" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("georgianacademy", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "georgianps" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("georgianps", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "pt154" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("pt154", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "viscii" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("viscii", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "iso646cn" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("iso646cn", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "iso646jp" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("iso646jp", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "hproman8" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("hproman8", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to a file with "tis620" encoding', function(done) {
|
||||||
|
checkWriteWithEncoding("tis620", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -875,5 +1256,373 @@ describe('file Nodes', function() {
|
|||||||
n1.receive({payload:""});
|
n1.receive({payload:""});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('encodings', function() {
|
||||||
|
|
||||||
|
function checkReadWithEncoding(enc, data, done) {
|
||||||
|
var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", "filename":fileToTest, "format":"utf8", encoding:enc, wires:[["n2"]]},
|
||||||
|
{id:"n2", type:"helper"}];
|
||||||
|
|
||||||
|
fs.writeFileSync(fileToTest, encode(data, enc));
|
||||||
|
helper.load(fileNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("fileInNode1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
try {
|
||||||
|
msg.should.have.property('payload');
|
||||||
|
msg.payload.should.be.a.String();
|
||||||
|
msg.payload.should.equal(data);
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({payload:""});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// default
|
||||||
|
it('should read in a file with "none" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("none", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Native
|
||||||
|
it('should read in a file with "utf8" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("utf8", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "ucs2" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("ucs2", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "utf-16le" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("utf-16le", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "binary" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("binary", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "base64" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("base64", "5pel5pys6KqeCg==", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "hex" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("hex", "deadbeef", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Unicode
|
||||||
|
it('should read in a file with "utf-16be" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("utf-16be", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Japanese
|
||||||
|
it('should read in a file with "Shift_JIS" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Shift_JIS", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "Windows-31j" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Windows-31j", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "Windows932" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Windows932", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "EUC-JP" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("EUC-JP", "試験", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// following encoding tests should be more specific
|
||||||
|
// Chinese
|
||||||
|
it('should read in a file with "GB2312" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("GB2312", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "GBK" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("GBK", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "GB18030" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("GB18030", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "Windows936" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Windows936", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "EUC-CN" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("EUC-CN", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Korean
|
||||||
|
it('should read in a file with "KS_C_5601" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("KS_C_5601", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "Windows949" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Windows949", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "EUC-KR" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("EUC-KR", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Taiwan/Hong Kong
|
||||||
|
it('should read in a file with "Big5" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Big5", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "Big5-HKSCS" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Big5-HKSCS", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "Windows950" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("Windows950", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Windows
|
||||||
|
it('should read in a file with "cp874" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp874", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1250" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1250", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1251" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1251", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1252" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1252", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1253" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1253", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1254" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1254", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1255" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1255", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1256" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1256", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1257" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1257", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1258" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1258", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// IBM
|
||||||
|
it('should read in a file with "cp437" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp437", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp737" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp737", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp775" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp775", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp808" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp808", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp850" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp850", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp852" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp852", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp855" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp855", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp856" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp856", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp857" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp857", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp858" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp858", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp860" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp860", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp861" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp861", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp866" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp866", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp869" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp869", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp922" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp922", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1046" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1046", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1124" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1124", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1125" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1125", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1129" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1129", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1133" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1133", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1161" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1161", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1162" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1162", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "cp1163" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("cp1163", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mac
|
||||||
|
it('should read in a file with "maccroatian" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("maccroatian", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "maccyrillic" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("maccyrillic", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "macgreek" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("macgreek", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "maciceland" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("maciceland", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "macroman" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("macroman", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "macromania" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("macromania", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "macthai" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("macthai", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "macturkish" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("macturkish", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "macukraine" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("macukraine", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "maccenteuro" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("maccenteuro", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "macintosh" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("macintosh", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// KOI8
|
||||||
|
it('should read in a file with "koi8-r" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("koi8-r", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "koi8-u" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("koi8-u", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "koi8-ru" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("koi8-ru", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "koi8-t" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("koi8-t", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
it('should read in a file with "armscii8" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("armscii8", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "rk1048" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("rk1048", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "tcvn" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("tcvn", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "georgianacademy" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("georgianacademy", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "georgianps" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("georgianps", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "pt154" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("pt154", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "viscii" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("viscii", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "iso646cn" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("iso646cn", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "iso646jp" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("iso646jp", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "hproman8" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("hproman8", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read in a file with "tis620" encoding', function(done) {
|
||||||
|
checkReadWithEncoding("tis620", "test", done);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user