Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
refactor: move to new timing API
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Dec 19, 2019
1 parent 4990e76 commit b85f092
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toReadableSizeString } from './util';
import log from './logger';
import request from 'request-promise';
import Ftp from 'jsftp';
import Timer from './timing';


async function uploadFileToHttp (remoteUrl, uploadOptions = {}) {
Expand Down Expand Up @@ -48,7 +49,7 @@ async function uploadFile (localPath, remotePath, uploadOptions = {}) {
const remoteUrl = url.parse(remotePath);
const {size} = await fs.stat(localPath);
log.info(`Uploading '${localPath}' of ${toReadableSizeString(size)} size to '${remotePath}'...`);
const timeStarted = process.hrtime();
const timer = new Timer().start();
if (['http:', 'https:'].includes(remoteUrl.protocol)) {
await uploadFileToHttp(remoteUrl, uploadOptions);
} else if (remoteUrl.protocol === 'ftp:') {
Expand All @@ -58,8 +59,7 @@ async function uploadFile (localPath, remotePath, uploadOptions = {}) {
`Unsupported remote protocol '${remoteUrl.protocol}'. ` +
`Only http/https and ftp protocols are supported.`);
}
const timeElapsed = process.hrtime(timeStarted)[0];
log.info(`Uploaded '${localPath}' of ${toReadableSizeString(size)} size in ${timeElapsed} second${timeElapsed === 1 ? '' : 's'}`);
log.info(`Uploaded '${localPath}' of ${toReadableSizeString(size)} size in ${timer.getDuration().asSeconds.toFixed(3)}s`);
}

export { uploadFile };

0 comments on commit b85f092

Please sign in to comment.