From 2104c69cb9475d52842d87530dd8439c08d7bbe5 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 16 May 2014 11:26:58 +0100 Subject: [PATCH] Stream files into zip in series --- .../Features/Downloads/ProjectZipStreamManager.coffee | 3 ++- .../coffee/Downloads/ProjectZipStreamManagerTests.coffee | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/web/app/coffee/Features/Downloads/ProjectZipStreamManager.coffee b/services/web/app/coffee/Features/Downloads/ProjectZipStreamManager.coffee index 579fdc7b41..d7f5c4054c 100644 --- a/services/web/app/coffee/Features/Downloads/ProjectZipStreamManager.coffee +++ b/services/web/app/coffee/Features/Downloads/ProjectZipStreamManager.coffee @@ -46,5 +46,6 @@ module.exports = ProjectZipStreamManager = return callback(err) path = path.slice(1) if path[0] == "/" archive.append stream, name: path - callback() + stream.on "end", () -> + callback() async.series jobs, callback diff --git a/services/web/test/UnitTests/coffee/Downloads/ProjectZipStreamManagerTests.coffee b/services/web/test/UnitTests/coffee/Downloads/ProjectZipStreamManagerTests.coffee index 61c6c40936..ba03d7cbc4 100644 --- a/services/web/test/UnitTests/coffee/Downloads/ProjectZipStreamManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Downloads/ProjectZipStreamManagerTests.coffee @@ -4,6 +4,7 @@ should = chai.should() expect = chai.expect modulePath = "../../../../app/js/Features/Downloads/ProjectZipStreamManager.js" SandboxedModule = require('sandboxed-module') +EventEmitter = require("events").EventEmitter describe "ProjectZipStreamManager", -> beforeEach -> @@ -112,14 +113,16 @@ describe "ProjectZipStreamManager", -> "/folder/picture.png": _id: "file-id-2" @streams = - "file-id-1" : "stream-mock-1" - "file-id-2" : "stream-mock-2" + "file-id-1" : new EventEmitter() + "file-id-2" : new EventEmitter() @ProjectEntityHandler.getAllFiles = sinon.stub().callsArgWith(1, null, @files) @archive.append = sinon.stub() @FileStoreHandler.getFileStream = (project_id, file_id, {}, callback) => callback null, @streams[file_id] sinon.spy @FileStoreHandler, "getFileStream" @ProjectZipStreamManager.addAllFilesToArchive @project_id, @archive, @callback + for path, stream of @streams + stream.emit "end" it "should get the files for the project", -> @ProjectEntityHandler.getAllFiles.calledWith(@project_id).should.equal true