Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

readfiletree

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readfiletree

Serialize a tree of files and directories into object form

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
152
-28.3%
Maintainers
1
Weekly downloads
 
Created
Source

readfiletree

NPM

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.

Requirements

Node.js >= 20

API

await readfiletree(directory)

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'
}

License

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.

Keywords

temp

FAQs

Package last updated on 16 Feb 2026

Did you know?

Socket

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.

Install

Related posts