directory-tree
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -18,9 +18,18 @@ 'use strict'; | ||
item.size = stats.size; // File size in bytes | ||
item.extension = ext; | ||
} | ||
else { | ||
item.children = FS.readdirSync(path) | ||
.map(child => directoryTree(PATH.join(path, child), extensions)) | ||
.filter(e => !!e); | ||
if (!item.children.length) return null; | ||
item.size = item.children.reduce((prev, cur) => prev + cur.size, 0); | ||
else if (stats.isDirectory()) { | ||
try { | ||
item.children = FS.readdirSync(path) | ||
.map(child => directoryTree(PATH.join(path, child), extensions)) | ||
.filter(e => !!e); | ||
if (!item.children.length) return null; | ||
item.size = item.children.reduce((prev, cur) => prev + cur.size, 0); | ||
} catch(ex) { | ||
if (ex.code == "EACCES") | ||
//User does not have permissions, ignore directory | ||
return null; | ||
} | ||
} else { | ||
return null; // Or set item.size = 0 for devices, FIFO and sockets ? | ||
} | ||
@@ -27,0 +36,0 @@ return item; |
{ | ||
"name": "directory-tree", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Convert a directory tree to a JS object.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -61,4 +61,5 @@ [![Build Status](https://travis-ci.org/mihneadb/node-directory-tree.svg)](https://travis-ci.org/mihneadb/node-directory-tree) | ||
"path": "photos/summer/june/windsurf.jpg", | ||
"name": "windsurf.jpg", | ||
"size": 400, | ||
"name": "windsurf.jpg", | ||
"extension": ".jpg" | ||
} | ||
@@ -83,2 +84,3 @@ ] | ||
"size": 100, | ||
"extension": ".png" | ||
}, | ||
@@ -89,2 +91,3 @@ { | ||
"size": 100, | ||
"extension": ".jpg" | ||
} | ||
@@ -98,5 +101,9 @@ ] | ||
``` | ||
## Note | ||
Device, FIFO and socket files are ignored. | ||
Files to which the user does not have permissions are included in the directory | ||
tree, however, directories to which the user does not have permissions, along | ||
with all of its contained files, are completely ignored. | ||
## Dev | ||
@@ -116,2 +123,1 @@ | ||
Check out version `0.1.1` if you need support for older versions of node. | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119
4151
5
33