首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Node.js中的EPIPE错误

Node.js中的EPIPE错误
EN

Stack Overflow用户
提问于 2018-08-14 18:28:11
回答 1查看 18K关注 0票数 7

以下代码可以在JPEG、Docx、zip和其他几种文件格式上正常运行。然后我在mpg-filer上尝试,但是,我被一个我无法调试的"Error: write EPIPE“击中。使用try/catch构造也会导致未捕获的异常。

代码:

var fs = require('fs')
const { spawn } = require('child_process')
var file = '/path/to/some/file.jpg'

var rs = fs.createReadStream(file)
const exiftool = spawn('exiftool', ['-json', '-']);
var exif = ''

exiftool.stdout.on('data', function(chunk) {
    exif += chunk
})

exiftool.on('close', function(code) {
    console.log('Sourcefile: %s', JSON.parse(exif)[0].SourceFile)
})

exiftool.on('error', function(error) {
    console.log('exiftool has error: %s', error)
})

rs.pipe(exiftool.stdin)

使用mpg-files时出现以下错误:

events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:835:14)
Emitted 'error' event at:
    at Socket.onerror (_stream_readable.js:687:12)
    at Socket.emit (events.js:182:13)
    at onwriteError (_stream_writable.js:431:12)
    at onwrite (_stream_writable.js:456:5)
    at _destroy (internal/streams/destroy.js:40:7)
    at Socket._destroy (net.js:605:3)
    at Socket.destroy (internal/streams/destroy.js:32:8)
    at WriteWrap.afterWrite [as oncomplete] (net.js:837:10)
EN

回答 1

Stack Overflow用户

发布于 2018-08-14 18:58:51

注释编辑:由于在中发现的问题,更正了代码

当您尝试写入关闭的流时,可能会发生此类错误

Try/Catch不是处理流错误的方法,但你可以这样做:

rs.pipe(exiftool.stdin).on('error', function(e) {
  console.log('rs.pipe has error: ' + e.message)
});
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51839293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档