
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
readfiletree
Advanced tools
Deserialize a file/directory tree into an object. Particularly useful for testing where you need to do a deepStrictEqual() on a simple tree of files. See mkfiletree for file tree serialization.
Node.js >= 20
Read the directory and the files it contains, recursively, and return an object representing the directory structure with nodes containing the utf8 string contents of each file.
Using both mkfiletree and readfiletree we can do the following:
import * as mkfiletree from 'mkfiletree'
import { readfiletree } from 'readfiletree'
const dir = await mkfiletree.makeTemp('testfiles',
{
'adir': {
'one.txt': '1\n2\n3\n',
'two.txt': 'a\nb\nc\n',
'deeper': {
'depths.txt': 'whoa...'
}
},
'afile.txt': 'file contents'
})
const obj = await readfiletree(dir)
console.log(obj)
The directory structure created above looks like the following:
$ find /tmp/testfiles11240-23530-r7rs3 -type f -exec sh -c "echo '\n{}: ' && cat '{}'" \;
/tmp/testfiles11240-23530-r7rs3/afile.txt:
file contents
/tmp/testfiles11240-23530-r7rs3/adir/deeper/depths.txt:
whoa...
/tmp/testfiles11240-23530-r7rs3/adir/two.txt:
a
b
c
/tmp/testfiles11240-23530-r7rs3/adir/one.txt:
1
2
3
And the output of the program should be the same as the input to mkfiletree:
{
'adir': {
'one.txt': '1\n2\n3\n',
'two.txt': 'a\nb\nc\n',
'deeper': {
'depths.txt': 'whoa...'
}
},
'afile.txt': 'file contents'
}
readfiletree is Copyright (c) 2012 Rod Vagg @rvagg and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
FAQs
Serialize a tree of files and directories into object form
The npm package readfiletree receives a total of 136 weekly downloads. As such, readfiletree popularity was classified as not popular.
We found that readfiletree demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.