Skip to content

Commit

Permalink
Merge pull request #41 from juzibot/fix-stream-bug
Browse files Browse the repository at this point in the history
Fix stream bug
  • Loading branch information
huan committed Oct 7, 2020
2 parents ba37e49 + e49a75a commit cf6caf5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "file-box",
"version": "0.13.8",
"version": "0.13.9",
"description": "Pack a File into Box for easy move/transfer between servers no matter of where it is.(local path, remote url, or cloud storage)",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand Down
10 changes: 7 additions & 3 deletions src/file-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class FileBox implements Pipeable {
}
return EMPTY_META_DATA
}

public set metadata (data: Metadata) {
if (this._metadata) {
throw new Error('metadata can not be modified after set')
Expand Down Expand Up @@ -388,7 +389,7 @@ export class FileBox implements Pipeable {
let obj: FileBoxJsonObject

switch (this.boxType) {
case FileBoxType.Url:
case FileBoxType.Url: {
if (!this.remoteUrl) {
throw new Error('no url')
}
Expand All @@ -402,8 +403,9 @@ export class FileBox implements Pipeable {
...objUrl,
}
break
}

case FileBoxType.QRCode:
case FileBoxType.QRCode: {
if (!this.qrCode) {
throw new Error('no qr code')
}
Expand All @@ -416,8 +418,9 @@ export class FileBox implements Pipeable {
...objQRCode,
}
break
}

case FileBoxType.Base64:
case FileBoxType.Base64: {
if (!this.base64) {
throw new Error('no base64 data')
}
Expand All @@ -430,6 +433,7 @@ export class FileBox implements Pipeable {
...objBase64,
}
break
}

default:
throw new Error('FileBox.toJSON() can only work on limited FileBoxType(s). See: <https://github.com/huan/file-box/issues/25>')
Expand Down
6 changes: 5 additions & 1 deletion src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export async function httpStream (
...headers,
}

const res = await new Promise<http.IncomingMessage>(resolve => get(options, resolve))
const res = await new Promise<http.IncomingMessage>((resolve, reject) => {
get(options, resolve)
.on('error', reject)
.end()
})
return res
}

Expand Down
2 changes: 1 addition & 1 deletion src/qrcode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('qrValueToStream()', async t => {
const stream = await qrValueToStream(QRCODE_VALUE)

const chunks = [] as Buffer[]
for await (let chunk of stream) {
for await (const chunk of stream) {
chunks.push(chunk as Buffer)
}
const buf = Buffer.concat(chunks)
Expand Down

0 comments on commit cf6caf5

Please sign in to comment.