Skip to content

Commit

Permalink
Zip folder before sending over aspera
Browse files Browse the repository at this point in the history
  • Loading branch information
mobalt committed Apr 20, 2021
1 parent 39f770d commit b1f3880
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uploader",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -14,13 +14,15 @@
"main": "background.js",
"dependencies": {
"about-window": "^1.13.2",
"adm-zip": "^0.5.5",
"axios": "^0.21.1",
"core-js": "^3.4.4",
"cryptr": "^2.0.0",
"electron-settings": "^3.2.0",
"fs-walk": "https://github.com/humanconnectome/fs-walk",
"node-datetime": "^2.1.2",
"ssh-keygen": "https://github.com/humanconnectome/ssh-keygen",
"temp": "^0.9.4",
"vue": "^2.6.10",
"vue-router": "^3.1.3"
},
Expand Down
43 changes: 42 additions & 1 deletion src/views/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const walk = require("fs-walk");
const path = require("path");
const fs = require("fs");
const os = require("os");
// const archiver = require('archiver');
const admZip = require("adm-zip");
const temp = require("temp").track();
const settings = require("electron-settings");
Expand All @@ -54,6 +57,44 @@ document.addEventListener("dragover", function(e) {
e.stopPropagation();
});
/**
* @param {String} source
* @param {String} out
* @returns {Promise}
*/
function zipDirectory_old(source) {
const archive = archiver('zip', { zlib: { level: 9 }});
const temp_path = temp.mkdirSync("dicom-uploader");
const out = path.join(temp_path, path.basename(source) + ".zip");
const stream = fs.createWriteStream(out);
console.log("Zipping:", source);
console.log("Saving zip to: ", out);
return new Promise((resolve, reject) => {
archive
.directory(source, false)
.on('error', err => reject(err))
.pipe(stream)
;
stream.on('close', () => {
console.log("Saved zip to: ", out);
return resolve(out)
} );
archive.finalize();
});
}
function zipDirectory(source) {
const temp_path = temp.mkdirSync("dicom-uploader");
const out = path.join(temp_path, path.basename(source) + ".zip");
const file = new admZip();
file.addLocalFolder(source);
console.log("Zipping:", source);
file.writeZip(out);
console.log("Finished zip to: ", out);
return out
}
export default {
data() {
return {
Expand Down Expand Up @@ -416,7 +457,7 @@ export default {
host,
this.project,
this.imageSessions[i].sessionLabel,
this.imageSessions[i].directory,
await zipDirectory(this.imageSessions[i].directory),
this.inboxPath,
key,
localLog,
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,11 @@ address@^1.1.2:
resolved "https://registry.yarnpkg.com/address/-/address-1.1.2.tgz#bf1116c9c758c51b7a933d296b72c221ed9428b6"
integrity sha512-aT6camzM4xEA54YVJYSqxz1kv4IHnQZRtThJJHhUMRExaU5spC7jX5ugSwTaTgJliIgs4VhZOk7htClvQ/LmRA==

adm-zip@^0.5.5:
version "0.5.5"
resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.5.5.tgz#b6549dbea741e4050309f1bb4d47c47397ce2c4f"
integrity sha512-IWwXKnCbirdbyXSfUDvCCrmYrOHANRZcc8NcRrvTlIApdl7PwE9oGcsYvNeJPAVY1M+70b4PxXGKIf8AEuiQ6w==

aggregate-error@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.1.0.tgz#92670ff50f5359bdb7a3e0d40d0ec30c5737687a"
Expand Down Expand Up @@ -8470,6 +8475,13 @@ rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rimraf@~2.6.2:
version "2.6.3"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
dependencies:
glob "^7.1.3"

ripemd160@^2.0.0, ripemd160@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c"
Expand Down Expand Up @@ -9401,6 +9413,14 @@ temp-file@^3.3.4:
async-exit-hook "^2.0.1"
fs-extra "^8.1.0"

temp@^0.9.4:
version "0.9.4"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.9.4.tgz#cd20a8580cb63635d0e4e9d4bd989d44286e7620"
integrity sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==
dependencies:
mkdirp "^0.5.1"
rimraf "~2.6.2"

term-size@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/term-size/-/term-size-1.2.0.tgz#458b83887f288fc56d6fffbfad262e26638efa69"
Expand Down

0 comments on commit b1f3880

Please sign in to comment.