Metadata-Version: 2.4
Name: pyfilehelpers
Version: 1.0.1
Summary: A Python library providing EOF check and lenfile count functions.
Author: Manjeet Yadav
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Dynamic: license-file

# PyFileHelpers

A lightweight, error-safe Python utility library providing `EOF()` status checking and `lenfile()` record counting without permanently altering file pointer positions.

---

## 📦 Installation

```bash
pip install pyfilehelpers

🚀 Functions Overview
1. EOF(file) / eof(file)

Checks if a file-like object has reached the End Of File (EOF) without changing the current file pointer position.

    Works with: Text files (.txt), Binary files (.bin, .jpg, .dat), and Memory buffers (BytesIO, StringIO).

    Returns:

        False → Data is available to read.

        True → End Of File reached (or file is closed/unreadable).

from pyfilehelpers import EOF

# Reading a text or binary file safely
with open("data.txt", "r") as f:
    while not EOF(f):
        line = f.readline()
        print(line, end="")

2. lenfile(file) / len_file(file)

Counts the total number of serialized (pickled) records stored inside a binary file without permanently changing the file pointer position.

    Works with: Binary files (rb) containing pickle.dump() objects.

    Returns: An integer representing the total record count (returns 0 if empty or invalid).

Example:
import pickle
from pyfilehelpers import lenfile

# Create a binary file with pickled records
with open("dataset.dat", "wb") as f:
    pickle.dump({"id": 101, "name": "Alice"}, f)
    pickle.dump({"id": 102, "name": "Bob"}, f)
    pickle.dump({"id": 103, "name": "Charlie"}, f)

# Count records in the binary file
with open("dataset.dat", "rb") as f:
    total = lenfile(f)
    print(f"Total Records: {total}")  # Output: Total Records: 3
    print(f"Current Pointer: {f.tell()}") # Pointer position is safely restored!

💡 Key Features

    Zero Side Effects: Always restores the original file cursor position using tell() and seek().
    Error Safe: Catches closed files, unreadable files, and corrupted data gracefully without crashing your program.
    PEP 8 Compliant: Supports both lowercase (eof, len_file) and uppercase (EOF, lenfile) naming conventions.
