Problem using ofURLFileLoader + MP3 File + Windows

Using ofURLFileLoader i download a mp3 file, and write it to the hard disk. On Mac, everything works just fine. Running the same script on Windows scrambles the MP3.

When I open the file in notepad, the difference between the original MP3 and the downloaded are some line breaks. It looks like ofURLFileLoader adds a line break after each buffer (1024).

Could someone give me a clue of how to remove/disable these line breaks?

mmh, are you using the saveTo function? it seems line 151:

  
ofFile saveTo(request.name,ofFile::WriteOnly);  

should be:

  
ofFile saveTo(request.name,ofFile::WriteOnly,true);  

so it uses binary mode which is surely the reason for the weird breaklines in windows.

can you test if that solves the problem for you so i can fix it in git

Hi Arturo,

Already tried that but it didn’t do any good.

What is the need of working with a buffer size of 1024 bytes? isn’t the request done at the moment the program reaches line 151? Can’t we just write the buffer to the file at once?

no cause it’s a network stream so you need to save it as it arrives

Found the solution!

It seems iOS::binary should be iOS_base::binary on windows.

function openStream, file: ofFileUtils.cpp, line 241

But it only work when i directly insert it into the function fstream::open() on line 250.
When is use the var binary_mode to hold the iOS_base::binary, it adds newlines [0x0D] again. Are these different types?

can you try changing the other flags to ios_base, like ios_base::in ios_base::out…

and see if that makes it work with the variable. it’s pretty weird that it doesn’t work as a var since it’s an enum, if they were different types it should fail when compiling