tomvlk / node-split-file

:seedling: NodeJS Module to split and merge files for several purposes like transporting over unstable networks.
MIT License
41 stars 13 forks source link

Truncated binary file #19

Closed chiarelli closed 7 years ago

chiarelli commented 7 years ago

I am separating and joining arbitrary binary files. The merged file has a different size from the original and is truncated.

chiarelli commented 7 years ago

The truncation problem also occurs in text files when using the "splitFileBySize ()" method, but with the "splitFile ()" method this problem does not occur.

When I changed the code of the "splitFileBySize ()" method:

---
// Number of parts (exclusive last part!)
 var parts = Math.floor(totalSize / maxSize);
---

for:

---
 // Number of parts (exclusive last part!)
  var parts = (totalSize / maxSize);
---

The problem was apparently solved. I believe that when size can not be rounded.

However, I believe it is more prudent to do more testing.

tomvlk commented 7 years ago

Hey @chiarelli. I'm not exactly sure, but I think that the rounding needs to use ceil instead of floor here, and therefor is a bug.

I will look into this asap. Do you have more information or a sample file for me?

chiarelli commented 7 years ago

Any file (binary or not) when it is splitted using splitFileBySize() and then merged results in a truncated file.

As an example you could try a zip file. As an example you could try a zip file: split it and then merge it, will result in a truncated file and different from the original (you will not be able to unzip it).

tomvlk commented 7 years ago

@chiarelli Released 2.1.0 for fixing this issue. I've not pushed it as a bugfix as it's chaging some behaviour.

Thanks for posting this issue!.