{"action":"opened","issue":{"url":"https://api.github.com/repos/leeroybrun/node-mt-files-downloader/issues/1","labels_url":"https://api.github.com/repos/leeroybrun/node-mt-files-downloader/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/leeroybrun/node-mt-files-downloader/issues/1/comments","events_url":"https://api.github.com/repos/leeroybrun/node-mt-files-downloader/issues/1/events","html_url":"https://github.com/leeroybrun/node-mt-files-downloader/issues/1","id":68780022,"number":1,"title":"Corrupted file downloads","user":{"login":"stormwalkerec","id":8964398,"avatar_url":"https://avatars.githubusercontent.com/u/8964398?v=3","gravatar_id":"","url":"https://api.github.com/users/stormwalkerec","html_url":"https://github.com/stormwalkerec","followers_url":"https://api.github.com/users/stormwalkerec/followers","following_url":"https://api.github.com/users/stormwalkerec/following{/other_user}","gists_url":"https://api.github.com/users/stormwalkerec/gists{/gist_id}","starred_url":"https://api.github.com/users/stormwalkerec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stormwalkerec/subscriptions","organizations_url":"https://api.github.com/users/stormwalkerec/orgs","repos_url":"https://api.github.com/users/stormwalkerec/repos","events_url":"https://api.github.com/users/stormwalkerec/events{/privacy}","received_events_url":"https://api.github.com/users/stormwalkerec/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-15T20:29:56Z","updated_at":"2015-04-15T20:29:56Z","closed_at":null,"body":"Could you please help me trace the issue:\r\n\r\nIf I download a file without resuming in any way, it works pretty much 100%\r\n\r\nHowever, the moment the file is resumed, its luck of the draw with most of the time the file throwing an error\r\n\r\nThe first time I received this error:\r\nDEMO - Resuming download...\r\nEVENT - Download 1 error !\r\n[Error: Invalid file path:  c:/test/10MBtest.bin.mtd]\r\nDownload 1 error : Error: Invalid file path:  c:/test/10MBtest.bin.mtd\r\n\r\nThe file was there, don't know why it was locked out.\r\n\r\nThe second time is the main issue I am facing:\r\nEVENT - Download 1 error !\r\n{ [Error: EPERM, ftruncate] errno: -4048, code: 'EPERM' }\r\nDownload 1 error : Error: EPERM, ftruncate\r\n\r\nThe file can balloon from 4-20 x its original size.\r\n\r\nHere's my test code, the file name can be set to 100MBtest.bin if your speed is to fast to receive the issue:\r\n\r\n```javascript\r\nvar os   = require('os');\r\nvar path = require('path');\r\nvar Downloader = require('mt-files-downloader');\r\n\r\n\r\n// Create new downloader\r\nvar downloader = new Downloader();\r\n\r\nvar fileUrl = 'http://speedtest.reliableservers.com/10MBtest.bin';\r\n//var fileSavePath = path.join(os.tmpdir(), 'mtFileDlTest1.zip');\r\nvar fileSavePath = 'c:/test/10MBtest.bin';\r\nconsole.log('File will be downloaded from '+ fileUrl +' to '+ fileSavePath);\r\n\r\n// Start download\r\nvar dl = downloader.download(fileUrl, fileSavePath);\r\n\r\n// Import generic examples for handling events and printing stats\r\nrequire('./_handleEvents')(dl);\r\nrequire('./_printStats')(dl);\r\n\r\ndl.start();\r\n\r\ndl.on('start', function() {\r\n    console.log('Download started with '+ ((dl.meta.threads) ? dl.meta.threads.length : 0) +' threads.')\r\n});\r\n\r\n// Wait 10s before stopping and then 4s before resuming download\r\ncycle();\r\n\r\nfunction cycle() {\r\n    setTimeout(function() {\r\n        console.log('DEMO - Stopping download... will be resumed in 2s');\r\n\r\n        dl.stop();\r\n\r\n        setTimeout(function() {\r\n            console.log('DEMO - Resuming download...');\r\n            dl.resume();\r\n            cycle();\r\n        }, 2000);\r\n    }, 5000);\r\n}\r\n```\r\n\r\nThe 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.\r\n\r\n"}}