Skip to content

Commit 0dcf4c2

Browse files
committed
Update README.rst
1 parent d1117bd commit 0dcf4c2

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

README.rst

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,80 @@
22
Python getdents
33
===============
44

5-
TBD
5+
Iterate large directories efficiently with python.
6+
7+
About
8+
=====
9+
10+
``python-getdents`` is a simple wrapper around Linux system call ``getdents64`` (see ``man getdents`` for details). `Here's <http://be-n.com/spw/you-can-list-a-million-files-in-a-directory-but-not-with-ls.html>`_ some study on why ``ls``, ``os.listdir()`` and others are so slow when dealing with extremely large directories.
11+
12+
13+
TODO
14+
====
15+
16+
* Verify that implementation works on platforms other than ``x86_64``.
17+
18+
* Add python2 support.
19+
20+
21+
Install
22+
=======
23+
24+
.. code-block:: python
25+
26+
pip install getdents
27+
28+
For development
29+
---------------
30+
31+
.. code-block:: python
32+
33+
python3 -m venv env
34+
. env/bin/activate
35+
pip install -e .
36+
37+
Run tests
38+
=========
39+
40+
.. code-block:: python
41+
42+
./setup.py test
43+
44+
Usage
45+
=====
46+
47+
.. code-block:: python
48+
49+
from getdents import getdents
50+
51+
for inode, type, name in getdents('/tmp', 32768):
52+
print(name)
53+
54+
Advanced
55+
--------
56+
57+
.. code-block:: python
58+
59+
import os
60+
from getdents import *
61+
62+
fd = os.open('/tmp', O_GETDENTS)
63+
64+
for inode, type, name in getdents_raw(fd, 2**20):
65+
print({
66+
DT_BLK: 'blockdev',
67+
DT_CHR: 'chardev ',
68+
DT_DIR: 'dir ',
69+
DT_FIFO: 'pipe ',
70+
DT_LNK: 'symlink ',
71+
DT_REG: 'file ',
72+
DT_SOCK: 'socket ',
73+
DT_UNKNOWN: 'unknown ',
74+
}[type], {
75+
True: 'd',
76+
False: ' ',
77+
}[inode == 0],
78+
name,
79+
)
80+
81+
os.close(fd)

0 commit comments

Comments
 (0)