From 8380b870dfb18a8cc85a437f9cb47cd805402301 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Mon, 18 Sep 2023 15:07:53 +0800 Subject: [PATCH] fix: use stat instead of statSync (#14) --- .github/workflows/nodejs.yml | 2 ++ .github/workflows/release.yml | 2 +- lib/object.js | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 4ed1c8d90..5bb62c67d 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -8,10 +8,12 @@ on: branches: - main - master + - 1.x pull_request: branches: - main - master + - 1.x jobs: build: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a4e1158fa..76cbd450b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Release on: push: - branches: [ master ] + branches: [ master, 1.x ] jobs: release: diff --git a/lib/object.js b/lib/object.js index 5c9beb413..6a230ac85 100644 --- a/lib/object.js +++ b/lib/object.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const { stat } = require('fs/promises'); const is = require('is-type-of'); const copy = require('copy-to'); const path = require('path'); @@ -59,12 +60,12 @@ proto.put = async function put(name, file, options) { if (Buffer.isBuffer(file)) { content = file; } else if (is.string(file)) { - const stats = fs.statSync(file); + const stats = await stat(file); if (!stats.isFile()) { throw new Error(`${file} is not file`); } options.mime = options.mime || mime.getType(path.extname(file)); - options.contentLength = await this._getFileSize(file); + options.contentLength = stats.size; const getStream = () => fs.createReadStream(file); const putStreamStb = (objectName, makeStream, configOption) => { return this.putStream(objectName, makeStream(), configOption);