file_read_backwards package

Submodules

file_read_backwards.buffer_work_space module

BufferWorkSpace module.

class file_read_backwards.buffer_work_space.BufferWorkSpace(fp, chunk_size)[source]

Bases: object

It is a helper module for FileReadBackwards.

add_to_buffer(content, read_position)[source]

Add additional bytes content as read from the read_position.

Args:
content (bytes): data to be added to buffer working BufferWorkSpac. read_position (int): where in the file pointer the data was read from.
has_returned_every_line()[source]

Return True if every single line in the file has been returned, False otherwise.

read_until_yieldable()[source]

Read in additional chunks until it is yieldable.

return_line()[source]

Return a new line if it is available.

Precondition: self.yieldable() must be True

yieldable()[source]

Return True if there is a line that the buffer can return, False otherwise.

file_read_backwards.file_read_backwards module

FileReadBackwards module.

class file_read_backwards.file_read_backwards.FileReadBackwards(path, encoding='utf-8', chunk_size=8192)[source]

Bases: object

Class definition for FileReadBackwards.

A FileReadBackwards will spawn a FileReadBackwardsIterator and keep an opened file handler.

It can be used as a Context Manager. If done so, when exited, it will close its file handler.

In any mode, close() can be called to close the file handler..

close()[source]

Closes all opened it s file handler.

readline()[source]

Return a line content (with a trailing newline) if there are content. Return ‘’ otherwise.

class file_read_backwards.file_read_backwards.FileReadBackwardsIterator(fp, encoding, chunk_size)[source]

Bases: object

Iterator for FileReadBackwards.

This will read backwards line by line a file. It holds an opened file handler.

close()[source]

Closes the file handler.

closed

The status of the file handler.

Returns:True if the file handler is still opened. False otherwise.
next()[source]

Returns unicode string from the last line until the beginning of file.

Gets exhausted if:

* already reached the beginning of the file on previous iteration
* the file got closed

When it gets exhausted, it closes the file handler.

Module contents