11-03-2016 08:12 PM
All binary read/write examples start with writing first, and then reading the known data type.
I would like to do a very simple thing: read an arbitrary file as a bytestream, format-independent, and then save same to another file.
For example, I would like to read an .avi file and then save read bytes into another file such, that by giving this new file the .avi extention I would be able to open it with windows tools as a movie.
I know it should be easy, but straightforward read/write with binary or text read/write did not work...
Thank you for your help --
Solved! Go to Solution.
11-03-2016 09:12 PM
Are you trying to copy the file? Use "Copy" on the Advanced File Functions.
Bob Schor
11-05-2016 09:00 AM
The super simple way is to just use the Copy function in the File IO->Advanced File Functions palette.
But if you want to do it the hard way, just use the Read From Binary File with a U8 for the data type (not an array) and -1 for the number of elements to read. Then use a Write To Binary File with the data you just read. Now for where you are likely having issues (this has bitten me many many times). There is a boolean input on the Write To Binary File called "prepend array or string size". Set that to FALSE. If that input is TRUE (default), then there will be an I32 written to the file before your byte array that tells whoever is reading how large the array is. You likely do not want that.
11-07-2016 10:37 AM
Thank you!
I need to read the file and then send in via a particular network loop, then receive it, compare with original and save the result. Therefore, "copy" would not work for me. Besides, sometimes you'd want to change just a few bytes of the file, keeping the rest intact, and save the result.
Thanks a lot for the info! I will try it and see how it works. I am surprized this rather simple procedure requires knowledge of so many nuances.. One would think the defaults would be set such that a simple binary string read with wiring the output to the input of another should do that.
Will let you know how it worked.
Regards --
11-08-2016 12:26 PM
I just implemented your suggestion and it works fine!
Thank you so much for helping with this --