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

refactor: move to new timing API #151

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };