Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Store a reference to res
this._response = res;
let fileName = this._response.headers["content-disposition"];
// Extract filename from header. Assumption is that the
// header is exactly as returned by the http service.
// Might throw errors for other headers
fileName = fileName.replace(`inline; filename="`, "");
// Remove trailing double quote
fileName = fileName.slice(0, fileName.length - 1);
// Get full file path
let filePath = Path.join(this.directory, fileName);
// Get unused filename
UnusedFileName(filePath)
.then(unusedpath => {
// Assign the file name to instance
this._filepath = unusedpath;
})
.then(() => {
// No point wrapping this in promise. Communication with
// outside world occurs through events
// Extract file size from header
this._size = parseInt(
this._response.headers["content-length"],
10
);
// Keep track of bytes downloaded
this._bytesDownloaded = 0;