node.js - Using named streams with clis without support for stdin -
i'm using following code read pdf web , pass pdftotext without saving in local file system:
const source = 'http://static.googleusercontent.com/media/research.google.com/en//archive/gfs-sosp2003.pdf' const http = require('http') const spawn = require('child_process').spawn  download(source).then(pdftotext) .then(result => console.log(result.slice(0, 77)))  function download(url) {   return new promise(resolve => http.get(url, resolve)) }  function pdftotext(binarystream) {   //read input stdin , write stdout   const command = spawn('pdftotext', ['-', '-'])   binarystream.pipe(command.stdin)    return new promise(resolve => {     const result = []     command.stdout.on('data', chunk => result.push(chunk.tostring()))     command.stdout.on('end', () => resolve(result.join('')))   }) }   in example, work because pdftotext supports stdin, if wasn't case, do? write named streams, didn't found it.
thanks in advance!
 
 
  
Comments
Post a Comment