Parser for binary exports generated by NCDU
Project description
ncdu-reader
Table of Contents
What is it?
ncdu-reader is a parser for binary exports generated by NCDU available since 2.6.
Usage
In order to parse a binary export generated by NCDU (i.e., ncdu -O export.bin), you can use the ncdu_reader.ncdu module.
from ncdu_reader import ncdu
export_path = "/tmp/export.bin"
root = ncdu.parse_ncdu(export_path)
For a simple file structure like this:
/tmp/ncdu-playground
└── foo
├── bar
│ ├── qux
│ └── quxx.bin
└── baz.bin
You will get this kind of output:
Parsed output
Directory(reference=AbsoluteReference(block_index=0, offset=126),
name='/tmp/ncdu-playground',
type=<ItemType.Directory: 0>,
prev=None,
asize=4096,
dsize=4096,
uid=None,
gid=None,
mode=None,
mtime=None,
dev=2096,
rderr=None,
cumasize=16384,
cumdsize=16384,
shrasize=0,
shrdsize=0,
items=5,
sub=RelativeReference(offset=-29),
children=[Directory(reference=AbsoluteReference(block_index=0,
offset=97),
name='foo',
type=<ItemType.Directory: 0>,
prev=None,
asize=4096,
dsize=4096,
uid=None,
gid=None,
mode=None,
mtime=None,
dev=0,
rderr=None,
cumasize=12288,
cumdsize=12288,
shrasize=0,
shrdsize=0,
items=4,
sub=RelativeReference(offset=-20),
children=[File(reference=AbsoluteReference(block_index=0,
offset=77),
name='baz.bin',
type=<ItemType.File: 1>,
prev=RelativeReference(offset=-29),
asize=0,
dsize=0,
uid=None,
gid=None,
mode=None,
mtime=None),
Directory(reference=AbsoluteReference(block_index=0,
offset=48),
name='bar',
type=<ItemType.Directory: 0>,
prev=None,
asize=4096,
dsize=4096,
uid=None,
gid=None,
mode=None,
mtime=None,
dev=0,
rderr=None,
cumasize=8192,
cumdsize=8192,
shrasize=0,
shrdsize=0,
items=2,
sub=RelativeReference(offset=-21),
children=[File(reference=AbsoluteReference(block_index=0,
offset=27),
name='quxx.bin',
type=<ItemType.File: 1>,
prev=RelativeReference(offset=-27),
asize=0,
dsize=0,
uid=None,
gid=None,
mode=None,
mtime=None),
Directory(reference=AbsoluteReference(block_index=0,
offset=0),
name='qux',
type=<ItemType.Directory: 0>,
prev=None,
asize=4096,
dsize=4096,
uid=None,
gid=None,
mode=None,
mtime=None,
dev=0,
rderr=None,
cumasize=4096,
cumdsize=4096,
shrasize=0,
shrdsize=0,
items=0,
sub=None,
children=[])])])])
For more information about what the different fields mean, refer to the official documentation.
Partial reads
ncdu-reader does not support lazily reading exports (e.g., parsing the root at first and then parsing children when requested). This means that the entire tree needs to be parsed at once. This can be problematic for very large exports.
It is however possible to only parse down to a certain depth, e.g. ncdu.parse_ncdu(export_path, depth=4). If all you care about is getting information about the top-level item (i.e., the root of your export), pass a depth of 0.
Performance
Here is a very unscientific benchmark of parsing exports for varying tree sizes to give an idea of scale, not expected performance. This includes the startup time for the Python interpreter, hence why small exports take around the same time.
| Tree Size | Time (mean ± σ) |
|---|---|
| 5 | 93.0 ms ± 1.6 ms |
| 12,605 | 95.1 ms ± 3.0 ms |
| 1,064,009 | 7.708 s ± 0.114 s |
| 7,905,281 | 87.761 s ± 0.710 s |
Note that RAM availability greatly impacts parsing of larger exports.
License
ncdu-reader is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ncdu_reader-1.0.0.tar.gz.
File metadata
- Download URL: ncdu_reader-1.0.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c23a533b79a8ea07af5f98b809828c7ce9e91c0fe5c57b79408b49daa0446e1b
|
|
| MD5 |
4322bd3dda083d7796250493c905e9df
|
|
| BLAKE2b-256 |
f7be1db68fef4aca1dab5da528b89dbfa73fa4710c4485af225da41e1d86cacc
|
File details
Details for the file ncdu_reader-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ncdu_reader-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8466eae7c70d74a3992dcce904ac8c9eb4c280d1ba64edf780df589d7680e0f7
|
|
| MD5 |
94370bf096a4957c3f486d972e266d0a
|
|
| BLAKE2b-256 |
1f34a95e71791e8dd9a7433245a842629d4198d0765ae52f2b950003863f9f40
|