Skip to content

Commit 0f8fc53

Browse files
committed
没必要费劲pipe
1 parent 398eae9 commit 0f8fc53

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

.release-it.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
npm:
2+
publish: true
3+
git:
4+
commit: true
5+
push: true
6+
tag: true
7+
hooks:
8+
after:version:bump: auto-changelog -p

src/index.ts

+7-21
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import is from '@sindresorhus/is'
22
import {createHmac} from 'crypto'
33
import {createReadStream} from 'fs'
44
import got, {Got, Options} from 'got'
5-
import {pipeline, Readable} from 'stream'
6-
import {finished} from 'stream/promises'
7-
import {promisify} from 'util'
5+
import {Readable} from 'stream'
86
import {EnumStorageClass} from './constant'
97
import {
108
IFinishMultipartUploadRes, IGetMultiUploadIdRes, IHeadFileRes, IInitiateMultipartUploadRes, IListObjectsRes, IOptions,
@@ -74,24 +72,12 @@ export class UFile {
7472
*/
7573
public async putFile(key: string, file: Buffer | Readable | string,
7674
mimeType = defaultMimeType): Promise<void> {
77-
if (is.buffer(file) || is.string(file)) {
78-
await this.got.put(key, {
79-
body: file,
80-
headers: {
81-
'content-type': mimeType,
82-
},
83-
})
84-
} else if (file instanceof Readable) {
85-
const req = this.got.put(key, {
86-
headers: {
87-
'content-type': mimeType,
88-
},
89-
isStream: true,
90-
})
91-
const res = file.pipe(req)
92-
await finished(res)
93-
}
94-
throw new TypeError('unknown file type')
75+
await this.got.put(key, {
76+
headers: {
77+
'content-type': mimeType,
78+
},
79+
body: file,
80+
})
9581
}
9682

9783
/**

0 commit comments

Comments
 (0)