0

I am using NODERED to read a serial port. The data coming in is 8 bit per byte. reading is working fine. Now, I want to write that buffer to a file.

When I use buffer.toString() it generates a string but with formatting. Even the 'binary' option escapes the data when 8th bit is set.

Howto write the raw data to a file without it getting changed?

Mission:

I want to generate a bitmap file, adding a fixed length image to the header.

Comparing the file with an hex editor with an existing bitmap shows the escaped bytes in the new file. Obviously that is wrong.

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
  • To write binary data, you do not want to use `toString()` -- could you update your post to include some sample buffer data, copied from the debug sidebar? – SteveR Jul 11 '18 at 14:50
  • well, it would be a simple 0xff that is saved as 0xC3 BF, or with other formatting something like 0xc2 0x90 in stead of 0x90. – Roozeboos Jul 11 '18 at 17:58
  • Oh and yes, I know now that toString is not the correct write function to use. The question is what does work.. – Roozeboos Jul 11 '18 at 18:08
  • Please add a bit of code so we can find out what you are trying to do. For writing a buffer inside a file you just need to do something like `fs.writeFile('image.bmp', Buffer)` – r3zaxd1 Jul 11 '18 at 22:28
  • Yes! fs is the way to go. didnt work at first because i was editing the wrong settings.js. :( . So writing using fs now works. I was using the file node and passing with msg.payload. That is wrong when writing this way. Thx – Roozeboos Jul 12 '18 at 08:26
  • @Roozeboos so I understand that your question is solved. I would suggest to document your solution in an answer and tag this question as answered. This way it is clear that the question is answered. – JanVdA Jul 16 '18 at 08:30

0 Answers0