bionode / bionode-watermill

💧Bionode-Watermill: A (Not Yet Streaming) Workflow Engine
https://bionode.gitbooks.io/bionode-watermill/content/
MIT License
37 stars 11 forks source link

Prevent Interference with Task Streams #3

Closed thejmazz closed 8 years ago

thejmazz commented 8 years ago

Task will return a readable, writable, or duplex stream. However, then the user, if they are making mischief, can interfere. Perhaps there is a use case for this, and it should just be advised to be avoided to not use stream methods on the streams that Task returns. Consider:

const config = {
  sraAccession: '2492428',
  referenceURL: 'http://ftp.ncbi.nlm.nih.gov/genomes/all/GCA_000988525.2_ASM98852v2/GCA_000988525.2_ASM98852v2_genomic.fna.gz'
}

// TODO take in an object stream to start off a bunch of these
const downloadReference = Task({
  input: config.referenceURL,
  output: new File(config.referenceURL.split('/').pop())
}, ({ input, output }) => request(input).pipe(fs.createWriteStream(output.value)) )

const s = downloadReference()
s.write('FOOBAR') // This gets written to the reference.gz file (and corrupts it)
s.on('finish', () => console.log('File written'))

Moreover something to keep in mind; probably not worthwhile finding a way to enforce this cannot happen instead of just advising to users to not do it unless they know what they are doing.