Use arrow functions for callbacks
This commit is contained in:
@ -6,26 +6,24 @@ const getFileStats = require('./getFileStats')
|
||||
const getFileType = require('./getFileType')
|
||||
|
||||
function getEntries(dir, file, maximumDepth) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readdir(path.join(dir, file), function(error, files) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(
|
||||
Promise.all(
|
||||
files.map(function(f) {
|
||||
return getFileStats(path.join(dir, file, f))
|
||||
})
|
||||
).then(function(statsArray) {
|
||||
files.map(f => getFileStats(path.join(dir, file, f)))
|
||||
).then(statsArray => {
|
||||
return Promise.all(
|
||||
statsArray.map(function(stats, index) {
|
||||
return getMetadataRecursive(
|
||||
statsArray.map((stats, index) =>
|
||||
getMetadataRecursive(
|
||||
dir,
|
||||
path.join(file, files[index]),
|
||||
stats,
|
||||
maximumDepth - 1
|
||||
)
|
||||
})
|
||||
)
|
||||
)
|
||||
})
|
||||
)
|
||||
@ -39,7 +37,7 @@ function formatTime(time) {
|
||||
}
|
||||
|
||||
function getIntegrity(file) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(file, function(error, data) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
@ -60,7 +58,7 @@ function getMetadataRecursive(dir, file, stats, maximumDepth) {
|
||||
}
|
||||
|
||||
if (stats.isFile()) {
|
||||
return getIntegrity(path.join(dir, file)).then(function(integrity) {
|
||||
return getIntegrity(path.join(dir, file)).then(integrity => {
|
||||
metadata.integrity = integrity
|
||||
return metadata
|
||||
})
|
||||
@ -69,7 +67,7 @@ function getMetadataRecursive(dir, file, stats, maximumDepth) {
|
||||
if (!stats.isDirectory() || maximumDepth === 0)
|
||||
return Promise.resolve(metadata)
|
||||
|
||||
return getEntries(dir, file, maximumDepth).then(function(files) {
|
||||
return getEntries(dir, file, maximumDepth).then(files => {
|
||||
metadata.files = files
|
||||
return metadata
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user