Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctx.body = stream 平台差异问题 #4822

Closed
norsl opened this issue Dec 3, 2021 · 3 comments
Closed

ctx.body = stream 平台差异问题 #4822

norsl opened this issue Dec 3, 2021 · 3 comments

Comments

@norsl
Copy link

norsl commented Dec 3, 2021

先看这个代码

ctx.attachment(path.parse(filename).base)
ctx.set('Content-Type', 'application/octet-stream')
ctx.set('Content-Length', stat.size)
ctx.body = fs.createReadStream(filePath)

在Windows上面能够正常下载文件,没什么问题。

然后我同样的代码再Ubuntu上面,body的值就变成了stream对象的json形式。每个文件的内容都是这个stream对象

{
    "_readableState": {
        "objectMode": false,
        "highWaterMark": 65536,
        "buffer": {
            "head": null,
            "tail": null,
            "length": 0
        },
        "length": 0,
        "pipes": [],
        "flowing": null,
        "ended": false,
        "endEmitted": false,
        "reading": false,
        "sync": true,
        "needReadable": false,
        "emittedReadable": false,
        "readableListening": false,
        "resumeScheduled": false,
        "errorEmitted": false,
        "emitClose": true,
        "autoDestroy": false,
        "destroyed": false,
        "errored": null,
        "closed": false,
        "closeEmitted": false,
        "defaultEncoding": "utf8",
        "awaitDrainWriters": null,
        "multiAwaitDrain": false,
        "readingMore": false,
        "dataEmitted": false,
        "decoder": null,
        "encoding": null
    },
    "_events": {},
    "_eventsCount": 2,
    "path": "/js/app.9e78b476.js",
    "fd": null,
    "flags": "r",
    "mode": 438,
    "end": null,
    "autoClose": true,
    "bytesRead": 0,
    "closed": false
}
@egg-bot
Copy link

egg-bot commented Dec 3, 2021

Hello @norsl. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@norsl,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

@norsl
Copy link
Author

norsl commented Dec 4, 2021

找到问题根源了,被自己蠢哭了

@norsl
Copy link
Author

norsl commented Dec 4, 2021

用了gzip中间件。但是这个gzip我并没有写完,导致body被JSON.stringify掉了。

@norsl norsl closed this as completed Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants