Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted file downloads #1

Open
stormwalkerec opened this issue Apr 15, 2015 · 6 comments
Open

Corrupted file downloads #1

stormwalkerec opened this issue Apr 15, 2015 · 6 comments

Comments

@stormwalkerec
Copy link

Could you please help me trace the issue:

If I download a file without resuming in any way, it works pretty much 100%

However, the moment the file is resumed, its luck of the draw with most of the time the file throwing an error

The first time I received this error:
DEMO - Resuming download...
EVENT - Download 1 error !
[Error: Invalid file path: c:/test/10MBtest.bin.mtd]
Download 1 error : Error: Invalid file path: c:/test/10MBtest.bin.mtd

The file was there, don't know why it was locked out.

The second time is the main issue I am facing:
EVENT - Download 1 error !
{ [Error: EPERM, ftruncate] errno: -4048, code: 'EPERM' }
Download 1 error : Error: EPERM, ftruncate

The file can balloon from 4-20 x its original size.

Here's my test code, the file name can be set to 100MBtest.bin if your speed is to fast to receive the issue:

var os   = require('os');
var path = require('path');
var Downloader = require('mt-files-downloader');


// Create new downloader
var downloader = new Downloader();

var fileUrl = 'http://speedtest.reliableservers.com/10MBtest.bin';
//var fileSavePath = path.join(os.tmpdir(), 'mtFileDlTest1.zip');
var fileSavePath = 'c:/test/10MBtest.bin';
console.log('File will be downloaded from '+ fileUrl +' to '+ fileSavePath);

// Start download
var dl = downloader.download(fileUrl, fileSavePath);

// Import generic examples for handling events and printing stats
require('./_handleEvents')(dl);
require('./_printStats')(dl);

dl.start();

dl.on('start', function() {
    console.log('Download started with '+ ((dl.meta.threads) ? dl.meta.threads.length : 0) +' threads.')
});

// Wait 10s before stopping and then 4s before resuming download
cycle();

function cycle() {
    setTimeout(function() {
        console.log('DEMO - Stopping download... will be resumed in 2s');

        dl.stop();

        setTimeout(function() {
            console.log('DEMO - Resuming download...');
            dl.resume();
            cycle();
        }, 2000);
    }, 5000);
}

The only other changes I made to your base code is to set the default threads to 6. I had them at 16 but found it replicated at lower numbers as well.

@leeroybrun
Copy link
Owner

Hello,

Sorry for the delay, I was quite busy with huge projects the past weeks.

I encountered this error too, but with a bigger file (1Gb), and have not found a solution for now to this. On my program, I currently restart the download if the file is corrupted. This is not ideal, especially with a big file, but this is the only workaround I've found for now.

Maybe this is coming from the main library "mt-downloader", but I'm not sure.

Does this append when the download/app crash and you try to resume the download, or when you stop the download and then try to resume it ?

Do you have found any new informations on this ?

@shainegordon
Copy link

This is actually very easy to reproduce.

Run the examples simple-download.js, and then run and cancel (Ctrl-C) resume-download.js a few times.

You will see mtFileDlTest1.zip increase.

@shainegordon
Copy link

possibly this issue in mt-downloader is fixed - tusharmath/Multi-threaded-downloader#36

I am going to try use the latest version of mt-downloader with this package

@shainegordon
Copy link

shainegordon commented Mar 6, 2016

I was able to fix this on windows, by updating FileHandlerAsyncTask.js in the mt-downloader package.

the change is how the file mode is set

var _execute = function(callback) {
    this.callback = callback;
    var self = this;
    var mode = 'a+';

becomes

var _execute = function(callback) {
    this.callback = callback;
    var self = this;
    var mode = 'r+';   // a+ becomes r+

because I am using this library on a legacy project, which doesn't actually use a package.json to manage the dependencies, and rather they are checked into source control, we just documented this change on our side.

that solution is not ideal, but it works in our scenario

@leeroybrun
Copy link
Owner

Thanks for your informations.

I will try to update to the latest mt-downloader version as soon as possible, maybe this will fix the problem.

You can follow the progress here if you're interested: #5

@hgouveia
Copy link

hgouveia commented Nov 7, 2017

i have same issue, and i can confirm that the solution from @shainegordon works great, changing var mode = 'a+'; to var mode = 'r+';

but is not ideal to change manually this file from mt-downloader on the node_modules

but this approach worked only with some files, another ones that were ok before now are corrupted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants