Skip to content

Commit

Permalink
Update README.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
ZipFile committed Dec 8, 2016
1 parent d1117bd commit 0dcf4c2
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,80 @@
Python getdents
===============

TBD
Iterate large directories efficiently with python.

About
=====

``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.


TODO
====

* Verify that implementation works on platforms other than ``x86_64``.

* Add python2 support.


Install
=======

.. code-block:: python
pip install getdents
For development
---------------

.. code-block:: python
python3 -m venv env
. env/bin/activate
pip install -e .
Run tests
=========

.. code-block:: python
./setup.py test
Usage
=====

.. code-block:: python
from getdents import getdents
for inode, type, name in getdents('/tmp', 32768):
print(name)
Advanced
--------

.. code-block:: python
import os
from getdents import *
fd = os.open('/tmp', O_GETDENTS)
for inode, type, name in getdents_raw(fd, 2**20):
print({
DT_BLK: 'blockdev',
DT_CHR: 'chardev ',
DT_DIR: 'dir ',
DT_FIFO: 'pipe ',
DT_LNK: 'symlink ',
DT_REG: 'file ',
DT_SOCK: 'socket ',
DT_UNKNOWN: 'unknown ',
}[type], {
True: 'd',
False: ' ',
}[inode == 0],
name,
)
os.close(fd)

0 comments on commit 0dcf4c2

Please sign in to comment.