mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge branch 'master' into dev
This commit is contained in:
commit
a04337a270
@ -194,6 +194,9 @@ Nodes
|
|||||||
- Watch: add msg.filename so can feed direct to file in node
|
- Watch: add msg.filename so can feed direct to file in node
|
||||||
- WebSocket: preserve \_session on msg but don't send as part of wholemsg
|
- WebSocket: preserve \_session on msg but don't send as part of wholemsg
|
||||||
|
|
||||||
|
#### 0.19.6: Maintenance Release
|
||||||
|
|
||||||
|
- Fix encoding of file node from binary to utf8 - #2051
|
||||||
|
|
||||||
#### 0.19.5: Maintenance Release
|
#### 0.19.5: Maintenance Release
|
||||||
|
|
||||||
|
@ -75,6 +75,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);
|
||||||
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;
|
||||||
@ -83,7 +84,7 @@ module.exports = function(RED) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
wstream.on("open", function() {
|
wstream.on("open", function() {
|
||||||
wstream.end(data, function() {
|
wstream.end(buf, function() {
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -132,13 +133,13 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
if (node.filename) {
|
if (node.filename) {
|
||||||
// Static filename - write and reuse the stream next time
|
// Static filename - write and reuse the stream next time
|
||||||
node.wstream.write(data, function() {
|
node.wstream.write(buf, function() {
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Dynamic filename - write and close the stream
|
// Dynamic filename - write and close the stream
|
||||||
node.wstream.end(data, function() {
|
node.wstream.end(buf, function() {
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
delete node.wstream;
|
delete node.wstream;
|
||||||
delete node.wstreamIno;
|
delete node.wstreamIno;
|
||||||
|
@ -79,6 +79,29 @@ describe('file Nodes', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should write multi-byte string to a file', function(done) {
|
||||||
|
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":true, 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).toString();
|
||||||
|
f.should.have.length(2);
|
||||||
|
f.should.equal("試験");
|
||||||
|
fs.unlinkSync(fileToTest);
|
||||||
|
msg.should.have.property("payload", "試験");
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({payload:"試験"});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should append to a file and add newline', function(done) {
|
it('should append to a file and add newline', function(done) {
|
||||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":false, wires: [["helperNode1"]]},
|
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":false, wires: [["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper"}];
|
{id:"helperNode1", type:"helper"}];
|
||||||
|
Loading…
Reference in New Issue
Block a user