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

Added zero padding when 10 or more files parts are needed #10

Closed purplecones closed 7 years ago

purplecones commented 7 years ago

I use this tool for splitting files and concatenating them later using cat *sf-part* > bundle.tar.gz. However, I ran into an issue when there are more than 10 parts. The reason is that cat sorts things in alphabetical order so given 10 files, cat *sf-part* > bundle.tar.gz would merge in this order:

file.sf-part1
file.sf-part10
file.sf-part2
file.sf-part3
...

and would result in an corrupt bundle.

To fix this, I made it so that the resulting file part names are padded with 0 as needed. So 14 parts would result the file part names to end in <file>.sf-part01, <file>.sf-part02, <file>.sf-part03, ... <file>.sf-part14

tomvlk commented 7 years ago

@purplecones I will look into this one later, maybe it's better to prepare a new version (with breaking changes) that contain changes like this.

purplecones commented 7 years ago

Ok thanks. We use this in our project meteor-now and definitely need this feature to avoid the issue above. Looking forward to updating the dependency once you merge it in.

tomvlk commented 7 years ago

@purplecones Great, I will freeze the 1.x version and make a separate branch for bugfixes for 1.x. This makes it possible to work on 2.x (breaking changes uppers the major number) with some new features like this.

Btw, Maybe it's even better to make it padding to three numbers to be sure with big number of parts.

Feel free to open more pull-requests if you need.

tomvlk commented 7 years ago

@purplecones ah nvm, saw that the padding is auto-adjusted. perfect!

tomvlk commented 7 years ago

@purplecones Released 2.0.0-alpha.1 with this functionality. 🥇