标签: through2

如何推迟流读取调用

streams一般来说,我仍然试图改变自己的方式.我已经能够从内部使用multiparty流式传输大型文件form.on('part').但我需要推迟调用并在读取之前解析流.我曾尝试PassThrough,through.through2,但已经得到了不同的结果,它主要挂起,我无法弄清楚该怎么做,也没有步骤调试.我对所有选择都持开放态度.感谢您的所有见解.

import multiparty from 'multiparty'
import {
  PassThrough
} from 'stream';
import through from 'through'
import through2 from 'through2'

export function promisedMultiparty(req) {
  return new Promise((resolve, reject) => {

    const form = new multiparty.Form()
    const form_files = []
    let q_str = ''

    form.on('field', (fieldname, value) => {
      if (value) q_str = appendQStr(fieldname, value, q_str)
    })

    form.on('part', async (part) => {
      if (part.filename) {

        const pass1 = new PassThrough() // …
Run Code Online (Sandbox Code Playgroud)

javascript through2 node-streams multiparty

10
推荐指数
1
解决办法
244
查看次数

为什么我的控制台记录:“TimeoutOverflowWarning:4294967296000 不适合 32 位有符号整数”

我正在学习stream-adventure课程。其中一项任务是创建一个 http 服务器,将所有请求转换为大写并在响应中返回。

现在我设法让它工作并且任务通过了。但是,控制台给了我一个 TimeoutOverflowWarning。

(node:15710) TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer.
Timer duration was truncated to 2147483647.
(node:15710) TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer.
Timer duration was truncated to 2147483647.
Run Code Online (Sandbox Code Playgroud)

我想知道这是内存泄漏还是由我的代码引起的,或者是否是其他原因。因为错误消息中提到了 32 位,我想知道这是否与我使用 2016 年的 Macbook Pro 以 64 位运行有关。(节点 v10.17.0)

代码:

'use-strict'
const through = require('through2')
const http = require('http')
const port = process.argv[2]

const uppercaser = through(function (buffer, _, next) {
  this.push(buffer.toString().toUpperCase())
  next()
});

const server = http.createServer(function …
Run Code Online (Sandbox Code Playgroud)

node.js through2

10
推荐指数
2
解决办法
2万
查看次数

NodeJS:2021 年干预 Steam 的“through2”的实际原生替代品

来自through2文档:

\n
\n

你需要这个吗?

\n

自从 Node.js 引入了简化流构造以来,\nthrough2 的许多使用都变得多余了。考虑您是否确实需要\n使用 through2 还是只想使用\'readable-stream\' 包或\n核心\'stream\' 包(源自\'readable-stream\')。

\n
\n

如果我理解正确的话,现在(从 2021 年开始)我们可以在没有第三方库的情况下干预流。\n我没有找到如何执行与Stream 文档through2中相同的操作。

\n
// ...\n  .pipe(through2(function (file, encoding, callback) {\n    // Do something with file ...\n    callback(null, file)\n   }))\n\n// \xe2\x86\x91 Possible to reach the same effect natively (with core packages)?\n
Run Code Online (Sandbox Code Playgroud)\n

我想,2021 年一定会有一些支持 async/await 语法的方法:

\n
// ...\n  .pipe(newFeatureOfModernNodeJS(async function (file) {\n\n    await doSomethingAsyncWithFile(file);\n    // on fail - same effect as "callback(new Error(\'...\'))" of trough2\n\n    return file; // …
Run Code Online (Sandbox Code Playgroud)

node.js through2

3
推荐指数
1
解决办法
596
查看次数

使用 Through2 从 Vinyl 流创建多个文件

我一直试图自己解决这个问题,但还没有成功。我什至不知道如何开始研究这个(虽然我已经尝试过一些谷歌搜索,但无济于事),所以我决定在这里问这个问题。

是否可以从 Through2 对象流返回多个 Vinyl 文件?

我的用例是这样的:我通过流接收一个 HTML 文件。我想隔离文件的两个不同部分(使用 jQuery)并将它们返回到两个单独的 HTML 文件中。我可以使用单个部分(以及单个生成的 HTML 文件)来完成此操作,但我完全不知道如何生成两个不同的文件。

有人可以帮我吗?提前致谢。

node.js gulp through2

2
推荐指数
1
解决办法
2594
查看次数

标签 统计

through2 ×4

node.js ×3

gulp ×1

javascript ×1

multiparty ×1

node-streams ×1