@lodestream/waveform-samples-generator
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -37,2 +37,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -45,24 +48,33 @@ if (mod && mod.__esModule) return mod; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var axios_1 = __importDefault(require("axios")); | ||
var debug_1 = __importDefault(require("debug")); | ||
var fs = __importStar(require("fs")); | ||
var axios_1 = __importDefault(require("axios")); | ||
var shell = __importStar(require("shelljs")); | ||
var tmp_dir_1 = require("./tmp-dir"); | ||
var debug = debug_1.default("download.ts"); | ||
exports.download = function (url) { return __awaiter(_this, void 0, void 0, function () { | ||
var downloadToFile, response; | ||
var dir, downloadToFile, response, fileStream; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
downloadToFile = tmp_dir_1.getTmpDir() + "/" + tmp_dir_1.extractFilename(url); | ||
debug("download()", url); | ||
dir = tmp_dir_1.getTmpDir(); | ||
shell.mkdir("-p", dir); | ||
downloadToFile = dir + "/" + tmp_dir_1.extractFilename(url); | ||
return [4 /*yield*/, axios_1.default({ url: url, responseType: "stream" })]; | ||
case 1: | ||
response = _a.sent(); | ||
response.data.pipe(fs.createWriteStream(downloadToFile)); | ||
return [2 /*return*/, { | ||
path: downloadToFile, | ||
clean: function () { return fs.unlinkSync(downloadToFile); } | ||
}]; | ||
fileStream = fs.createWriteStream(downloadToFile); | ||
response.data.pipe(fileStream); | ||
return [2 /*return*/, new Promise(function (resolve) { | ||
fileStream.on("close", function () { | ||
debug("File saved to", downloadToFile); | ||
resolve({ | ||
path: downloadToFile, | ||
clean: function () { return fs.unlinkSync(downloadToFile); } | ||
}); | ||
}); | ||
})]; | ||
} | ||
@@ -69,0 +81,0 @@ }); |
{ | ||
"name": "@lodestream/waveform-samples-generator", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"main": "lib/index.js", | ||
@@ -18,3 +18,5 @@ "author": { | ||
"dependencies": { | ||
"@types/debug": "^0.0.31", | ||
"axios": "^0.18.0", | ||
"debug": "^4.1.1", | ||
"lodash": "^4.17.11", | ||
@@ -31,6 +33,6 @@ "shelljs": "^0.8.3", | ||
"@types/shelljs": "^0.8.1", | ||
"jest": "^23.6.0", | ||
"rimraf": "^2.6.2", | ||
"jest": "^23.6.0", | ||
"ts-jest": "^23.10.5" | ||
} | ||
} |
@@ -0,14 +1,31 @@ | ||
import Axios from "axios"; | ||
import _debug from "debug"; | ||
import * as fs from "fs"; | ||
import * as shell from "shelljs"; | ||
import * as fs from "fs"; | ||
import Axios from "axios"; | ||
import { getTmpDir, extractFilename } from "./tmp-dir"; | ||
const debug = _debug("download.ts"); | ||
interface IDownloadReturn { | ||
path: string; | ||
clean: () => void; | ||
} | ||
export const download = async (url: string) => { | ||
const downloadToFile = `${getTmpDir()}/${extractFilename(url)}`; | ||
debug("download()", url); | ||
const dir = getTmpDir(); | ||
shell.mkdir("-p", dir); | ||
const downloadToFile = `${dir}/${extractFilename(url)}`; | ||
const response = await Axios({ url, responseType: "stream" }); | ||
response.data.pipe(fs.createWriteStream(downloadToFile)); | ||
return { | ||
path: downloadToFile, | ||
clean: () => fs.unlinkSync(downloadToFile) | ||
}; | ||
const fileStream = fs.createWriteStream(downloadToFile); | ||
response.data.pipe(fileStream); | ||
return new Promise<IDownloadReturn>(resolve => { | ||
fileStream.on("close", () => { | ||
debug("File saved to", downloadToFile); | ||
resolve({ | ||
path: downloadToFile, | ||
clean: () => fs.unlinkSync(downloadToFile) | ||
}); | ||
}); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
873945
32
590
8
+ Added@types/debug@^0.0.31
+ Addeddebug@^4.1.1
+ Added@types/debug@0.0.31(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedms@2.1.3(transitive)