Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// We map a hash to multiple fileObj's because the same file
// might live in two different locations
if (Array.isArray(shaMap[fileObj.hash])) {
shaMap[fileObj.hash].push(fileObj)
} else {
shaMap[fileObj.hash] = [fileObj]
}
cb(null)
})
}
// transform stream ctor that filters folder-walker results for only files
exports.fileFilterCtor = objFilterCtor(fileObj => {
return fileObj.type === 'file'
})
exports.fnFilterCtor = objFilterCtor(fileObj => {
// filter additional files out of our fn pipeline
return fileObj.type === 'file' && !!fileObj.runtime
})
// Zip a file into a temporary directory
function zipFunction(item, tmpDir, cb) {
const zipPath = path.join(tmpDir, item.normalizedPath + '.zip')
const output = fs.createWriteStream(zipPath)
const archive = archiver('zip')
archive.file(item.filepath, { name: item.basename })
archive.finalize()
module.exports = makeTrackDict
function makeTrackDict (paths, cb) {
var newTrackDict = {}
var dest = concatTrackDict(newTrackDict)
pump(walker(paths), FileFilter(), dest, handleEos)
// Return dest so we can destroy it
return dest
function handleEos (err) {
if (err) return cb(err)
log.info('')
cb(null, newTrackDict)
}
}
var FileFilter = filter.objCtor(isValidFile)
function isValidFile (data, enc, cb) {
if (data.type !== 'file') return false
var ext = path.extname(data.basename).substring(1)
return validExtensions.includes(ext)
}
function concatTrackDict (obj) {
function writeTrackDict (data, enc, cb) {
log.info(`Scanning ${data.filepath}`)
parseMetadata(data, handleMeta)
function handleMeta (err, meta) {
if (err) throw err
obj[meta.filepath] = meta
cb(null)
if (Array.isArray(shaMap[fileObj.hash])) {
shaMap[fileObj.hash].push(fileObj)
} else {
shaMap[fileObj.hash] = [fileObj]
}
cb(null)
})
}
// transform stream ctor that filters folder-walker results for only files
exports.fileFilterCtor = objFilterCtor(fileObj => {
return fileObj.type === 'file'
})
exports.fnFilterCtor = objFilterCtor(fileObj => {
// filter additional files out of our fn pipeline
return fileObj.type === 'file' && !!fileObj.runtime
})
// Zip a file into a temporary directory
function zipFunction(item, tmpDir, cb) {
const zipPath = path.join(tmpDir, item.normalizedPath + '.zip')
const output = fs.createWriteStream(zipPath)
const archive = archiver('zip')
archive.file(item.filepath, { name: item.basename })
archive.finalize()
pump(archive, output, err => {
if (err) return cb(err)
if (Array.isArray(shaMap[fileObj.hash])) {
shaMap[fileObj.hash].push(fileObj)
} else {
shaMap[fileObj.hash] = [fileObj]
}
statusCb({
type: 'hashing',
msg: `Hashing ${fileObj.relname}`,
phase: 'progress'
})
cb(null)
})
}
// transform stream ctor that filters folder-walker results for only files
exports.fileFilterCtor = objFilterCtor(fileObj => {
return fileObj.type === 'file'
})