Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.flatMap((fileReader: FileReaderType) => {
const readResult: FileReaderResultType = {
filename: filename,
notePropName: fileReader.notePropName,
value: null
}
return Bacon
.fromNodeCallback(fileReader.read.bind(fileReader), notesPath.fullPath(filename), fileStats)
.map(value => {
readResult.value = value === undefined ? null : value // make sure value cannot be undefined
return readResult
})
.mapError(err => {
console.warn('failed to read file:', err)
return readResult
})
})
})
function loadApplicationConf (ignoreParentConfig = false, pathToFolder) {
if (pathToFolder == null) {
pathToFolder = path.dirname(conf.APP_CONFIGURATION_FILE);
}
const fileName = path.basename(conf.APP_CONFIGURATION_FILE);
const fullPath = path.join(pathToFolder, fileName);
Logger.debug('Loading app configuration from ' + fullPath);
return Bacon.fromNodeCallback(fs.readFile, fullPath)
.flatMapLatest(Bacon.try(JSON.parse))
.flatMapError((error) => {
Logger.info('Cannot load app configuration from ' + conf.APP_CONFIGURATION_FILE + ' (' + error + ')');
if (ignoreParentConfig || path.parse(pathToFolder).root === pathToFolder) {
return { apps: [] };
}
return loadApplicationConf(ignoreParentConfig, path.normalize(path.join(pathToFolder, '..')));
});
};
function mongoFind(query) {
return Bacon.fromNodeCallback(turtles.find(query).limit(100).sort({date: -1}), "toArray")
}
function sendResult(resultE, res) {
function mongoPost(data) {
return Bacon.fromNodeCallback(turtles, "insert", [data])
}
function mongoFind(query) {
function fetchUrl(url, bodyIsBinary) {
if (responseCache[url]) {
return Bacon.later(0, responseCache[url])
}
return Bacon.fromNodeCallback((callback) => {
request(url, { timeout: 20000, encoding: bodyIsBinary ? null : undefined }, (error, response, body) => {
if (!error && response.statusCode == 200) {
if (!url.endsWith('.tgz')) {
responseCache[url] = body
}
callback(null, body)
} else {
const statusCode = response ? response.statusCode : 'n/a'
callback(`Failed to fetch ${url} because of error '${error}' and/or HTTP status ${statusCode}`)
}
})
})
}
}).flatMap(function (input) {
return Bacon.fromNodeCallback(fs.open, input.name, 'r').map(function (fd) {
return {
fd: fd,
size: input.size,
read: 0
};
});
}).onValue(function (input) {
readerStream.push(input);
.flatMap(({path}) => {
return Bacon
.fromNodeCallback(this.darwin.getTags, path)
.map(([tags]) => ({
path: path,
tags: tags.join(' ')
}))
})
.filter(R.is(Object))