次のコードは、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 ファイル使用時のエラー:
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)