readx 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- readx-0.1.0/LICENSE +21 -0
- readx-0.1.0/PKG-INFO +64 -0
- readx-0.1.0/README.md +54 -0
- readx-0.1.0/pyproject.toml +18 -0
- readx-0.1.0/setup.cfg +4 -0
- readx-0.1.0/src/__init__.py +5 -0
- readx-0.1.0/src/readx.egg-info/PKG-INFO +64 -0
- readx-0.1.0/src/readx.egg-info/SOURCES.txt +9 -0
- readx-0.1.0/src/readx.egg-info/dependency_links.txt +1 -0
- readx-0.1.0/src/readx.egg-info/top_level.txt +2 -0
- readx-0.1.0/src/readx.py +40 -0
readx-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Beks1k
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
readx-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: readx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lib for easy use of discord webhook
|
|
5
|
+
Author: Beks1k
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# readx
|
|
12
|
+
|
|
13
|
+
A micro-library for safe file reading and size inspection. Protects your terminal and memory from crashing when accidentally reading huge or binary files.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Safe Reading**: Automatically stops and raises an error if the file is binary or too large.
|
|
18
|
+
- **Smart Size**: Converts bytes to KB, MB, or GB into clean integer or float values.
|
|
19
|
+
- **No Dependencies**: Built entirely using Python's standard library.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Just drop the script into your project folder or install it:
|
|
24
|
+
```bash
|
|
25
|
+
pip install readx
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### 1. Safe Content Reading
|
|
31
|
+
By default, `readContent` blocks files larger than 200MB or files with binary structures.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import readx
|
|
35
|
+
|
|
36
|
+
# Reading a safe text file
|
|
37
|
+
text = readx.readContent("logs.txt")
|
|
38
|
+
|
|
39
|
+
# Trying to read a 1GB database or a .png image without ignoreWarns=True
|
|
40
|
+
# Will safely raise TooBig or BinaryFile exceptions instead of freezing your PC
|
|
41
|
+
binary_data = readx.readContent("photo.png", ignoreWarns=True)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. Smart File Size Conversion
|
|
45
|
+
Convert file size into any format without messy `if/else` lines.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import readx
|
|
49
|
+
|
|
50
|
+
# Returns an exact integer if there is no remainder, or float if there is
|
|
51
|
+
mb_size = readx.size("video.mp4", type="MB") # e.g., 45 or 45.23
|
|
52
|
+
gb_size = readx.size("archive.zip", type="GB")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Custom Exceptions
|
|
56
|
+
|
|
57
|
+
The library provides clear exceptions you can handle with `try/except`:
|
|
58
|
+
- `FileNotFound` - Raised when the path does not exist.
|
|
59
|
+
- `TooBig` - Raised when the file exceeds the threshold.
|
|
60
|
+
- `BinaryFile` - Raised when trying to read a binary file in text mode.
|
|
61
|
+
- `InvalidType` - Raised when a wrong size format is requested.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
MIT
|
readx-0.1.0/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# readx
|
|
2
|
+
|
|
3
|
+
A micro-library for safe file reading and size inspection. Protects your terminal and memory from crashing when accidentally reading huge or binary files.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Safe Reading**: Automatically stops and raises an error if the file is binary or too large.
|
|
8
|
+
- **Smart Size**: Converts bytes to KB, MB, or GB into clean integer or float values.
|
|
9
|
+
- **No Dependencies**: Built entirely using Python's standard library.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Just drop the script into your project folder or install it:
|
|
14
|
+
```bash
|
|
15
|
+
pip install readx
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### 1. Safe Content Reading
|
|
21
|
+
By default, `readContent` blocks files larger than 200MB or files with binary structures.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import readx
|
|
25
|
+
|
|
26
|
+
# Reading a safe text file
|
|
27
|
+
text = readx.readContent("logs.txt")
|
|
28
|
+
|
|
29
|
+
# Trying to read a 1GB database or a .png image without ignoreWarns=True
|
|
30
|
+
# Will safely raise TooBig or BinaryFile exceptions instead of freezing your PC
|
|
31
|
+
binary_data = readx.readContent("photo.png", ignoreWarns=True)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 2. Smart File Size Conversion
|
|
35
|
+
Convert file size into any format without messy `if/else` lines.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import readx
|
|
39
|
+
|
|
40
|
+
# Returns an exact integer if there is no remainder, or float if there is
|
|
41
|
+
mb_size = readx.size("video.mp4", type="MB") # e.g., 45 or 45.23
|
|
42
|
+
gb_size = readx.size("archive.zip", type="GB")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Custom Exceptions
|
|
46
|
+
|
|
47
|
+
The library provides clear exceptions you can handle with `try/except`:
|
|
48
|
+
- `FileNotFound` - Raised when the path does not exist.
|
|
49
|
+
- `TooBig` - Raised when the file exceeds the threshold.
|
|
50
|
+
- `BinaryFile` - Raised when trying to read a binary file in text mode.
|
|
51
|
+
- `InvalidType` - Raised when a wrong size format is requested.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "readx"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
description = "Lib for easy use of discord webhook"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Beks1k"}
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
[tool.setuptools]
|
|
17
|
+
# Указываем setuptools искать пакеты строго внутри директории src
|
|
18
|
+
package-dir = {"" = "src"}
|
readx-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: readx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lib for easy use of discord webhook
|
|
5
|
+
Author: Beks1k
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# readx
|
|
12
|
+
|
|
13
|
+
A micro-library for safe file reading and size inspection. Protects your terminal and memory from crashing when accidentally reading huge or binary files.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Safe Reading**: Automatically stops and raises an error if the file is binary or too large.
|
|
18
|
+
- **Smart Size**: Converts bytes to KB, MB, or GB into clean integer or float values.
|
|
19
|
+
- **No Dependencies**: Built entirely using Python's standard library.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Just drop the script into your project folder or install it:
|
|
24
|
+
```bash
|
|
25
|
+
pip install readx
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### 1. Safe Content Reading
|
|
31
|
+
By default, `readContent` blocks files larger than 200MB or files with binary structures.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import readx
|
|
35
|
+
|
|
36
|
+
# Reading a safe text file
|
|
37
|
+
text = readx.readContent("logs.txt")
|
|
38
|
+
|
|
39
|
+
# Trying to read a 1GB database or a .png image without ignoreWarns=True
|
|
40
|
+
# Will safely raise TooBig or BinaryFile exceptions instead of freezing your PC
|
|
41
|
+
binary_data = readx.readContent("photo.png", ignoreWarns=True)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. Smart File Size Conversion
|
|
45
|
+
Convert file size into any format without messy `if/else` lines.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import readx
|
|
49
|
+
|
|
50
|
+
# Returns an exact integer if there is no remainder, or float if there is
|
|
51
|
+
mb_size = readx.size("video.mp4", type="MB") # e.g., 45 or 45.23
|
|
52
|
+
gb_size = readx.size("archive.zip", type="GB")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Custom Exceptions
|
|
56
|
+
|
|
57
|
+
The library provides clear exceptions you can handle with `try/except`:
|
|
58
|
+
- `FileNotFound` - Raised when the path does not exist.
|
|
59
|
+
- `TooBig` - Raised when the file exceeds the threshold.
|
|
60
|
+
- `BinaryFile` - Raised when trying to read a binary file in text mode.
|
|
61
|
+
- `InvalidType` - Raised when a wrong size format is requested.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
readx-0.1.0/src/readx.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from expections import(
|
|
4
|
+
FileNotFound, TooBig, BinaryFile, InvalidType
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
def readContent(path:str, ignoreWarns = False, treshHold:int = 209715200):
|
|
8
|
+
if not path:
|
|
9
|
+
raise ValueError("PATH CANT BE EMPTY")
|
|
10
|
+
if not os.path.exists(path):
|
|
11
|
+
raise FileNotFound("PATH DONT EXSITS")
|
|
12
|
+
if os.path.getsize(path) > treshHold:
|
|
13
|
+
if not ignoreWarns:
|
|
14
|
+
raise TooBig("FILE TOO BIG")
|
|
15
|
+
try:
|
|
16
|
+
with open(path, "r", encoding="utf-8") as file:
|
|
17
|
+
data = file.read()
|
|
18
|
+
except UnicodeDecodeError:
|
|
19
|
+
if not ignoreWarns:
|
|
20
|
+
raise BinaryFile("FILE IS BINARY")
|
|
21
|
+
|
|
22
|
+
with open(path, "rb") as file:
|
|
23
|
+
data = file.read()
|
|
24
|
+
return data
|
|
25
|
+
|
|
26
|
+
def size(path:str, type:str = "MB"):
|
|
27
|
+
if not path:
|
|
28
|
+
raise ValueError("PATH CANT BE EMPTY")
|
|
29
|
+
if not os.path.exists(path):
|
|
30
|
+
raise FileNotFound("PATH DONT EXSITS")
|
|
31
|
+
types = ["B", "KB", "MB", "GB"]
|
|
32
|
+
siz = os.path.getsize(path)
|
|
33
|
+
if type in types:
|
|
34
|
+
index = 1024 ** types.index(type)
|
|
35
|
+
if siz % index == 0:
|
|
36
|
+
return siz // index
|
|
37
|
+
else:
|
|
38
|
+
return siz / index
|
|
39
|
+
else:
|
|
40
|
+
raise InvalidType(f"INVALID TYPE MUST BE ONE OF {types}")
|