Skip to content
Permalink
Browse files

fix(server): use safePipe() to pipe files

  • Loading branch information...
mycoboco committed Jul 9, 2019
1 parent 1a69b12 commit 611400a4a3c1a7e26ff26b25ca26c6cfb550e09b
Showing with 8 additions and 15 deletions.
  1. +2 −7 server/lib/api.js
  2. +3 −4 server/lib/db.mongo.js
  3. +3 −4 server/lib/db.ne.js
@@ -13,6 +13,7 @@ var hodgepodge = {
}

var mp3 = require('./mp3')
var safePipe = require('./safePipe')


var log, db, daap, conf
@@ -326,13 +327,7 @@ function song(req, res) {
})
rs = fs.createReadStream(songs[0].path)
}
// workaround for broken pipe; old stream has no destroy()
res.on('unpipe', function () {
rs.once('readable', function () { rs.close() })
})
res.on('error', function () { rs.unpipe(res) })
.on('close', function () { rs.unpipe(res) })
rs.pipe(res)
safePipe(rs, res, function (err) { log.error(err) })
})
})
}
@@ -16,6 +16,8 @@ var hodgepodge = {
mongoose: require('hodgepodge-node/mongoose')(mongoose)
}

var safePipe = require('./safePipe')

var infoSchema = new Schema({
type: {
index: true,
@@ -243,10 +245,7 @@ function cacheRead(name, metas, to, cb) {
rs = gfs.createReadStream({ filename: name })

log.info('reading cache for '+name)
rs.on('error', cb)
to.on('error', function () { rs.close() })
.on('close', function () { rs.close() })
rs.pipe(to)
safePipe(rs, to, cb)
}


@@ -15,6 +15,8 @@ var async = require('async')
var mkdirp = require('mkdirp')
var logger = require('hodgepodge-node/logger')

var safePipe = require('./safePipe')


var log, conf

@@ -189,10 +191,7 @@ function cacheRead(name, metas, to, cb) {
rs = fs.createReadStream(name)

log.info('reading cache for '+name)
rs.on('error', cb)
to.on('error', function () { rs.close() })
.on('close', function () { rs.close() })
rs.pipe(to)
safePipe(rs, to, cb)
}


0 comments on commit 611400a

Please sign in to comment.
You can’t perform that action at this time.