File slice is a part of a file. This library allows you to open a binary file and see only part of it.
Project description
:Date: 2018-10-10
:Version: 0.0.1
:Authors:
- Mohammad Alghafli <thebsom@gmail.com>
File slice is a part of a file. This library allows you to open a binary file
and see only part of it. You specify the start and end of the file part you want
to see. Read and write operations will always start at the specified start
position and will never exceed the specified end position. Here is an example of
how to use it::
from fileslice import Slicer
#let's open a file for reading
r = open('example.png', 'br')
#create a slicer for the file
slicer = Slicer(r)
#the slicer behaves like a function. call it to create as many fileslices
#as you want
start = 5 #the beginning of our partial file is at 5
size = 95 #the size of the part is 95 bytes so our end is 99
fileslice = slicer (start, size) #this is a file like object
#now we have a fileslice file from byte 5 to byte 99.
#the initial partial file seek position is 0.
print(fileslice.read()) #will print from byte 5 to 99.
#now our seek position is at the end of the fileslice file
#that is byte 100 of the full file
try:
#if we seek to a position out of the fileslice file range (from 0 to 95)
fileslice.seek(200)
except ValueError:
#an exception will be thrown
print('error while seeking to 200')
#we can seek from the end of the fileslice or from current fileslice
#seek position
#let's seek to fifth byte from the end of the file. that is byte 95
fileslice.seek(-5, 2)
This library also works in writable files. Multiple threads can be used to read
and write to different file slices from the same file. Just make sure you do not
use the original opened file or the fileslices (and the original file object)
will be confused.
--------
Tutorial
--------
Check out fileslice tutorial at http://fileslice.readthedocs.io/
:Version: 0.0.1
:Authors:
- Mohammad Alghafli <thebsom@gmail.com>
File slice is a part of a file. This library allows you to open a binary file
and see only part of it. You specify the start and end of the file part you want
to see. Read and write operations will always start at the specified start
position and will never exceed the specified end position. Here is an example of
how to use it::
from fileslice import Slicer
#let's open a file for reading
r = open('example.png', 'br')
#create a slicer for the file
slicer = Slicer(r)
#the slicer behaves like a function. call it to create as many fileslices
#as you want
start = 5 #the beginning of our partial file is at 5
size = 95 #the size of the part is 95 bytes so our end is 99
fileslice = slicer (start, size) #this is a file like object
#now we have a fileslice file from byte 5 to byte 99.
#the initial partial file seek position is 0.
print(fileslice.read()) #will print from byte 5 to 99.
#now our seek position is at the end of the fileslice file
#that is byte 100 of the full file
try:
#if we seek to a position out of the fileslice file range (from 0 to 95)
fileslice.seek(200)
except ValueError:
#an exception will be thrown
print('error while seeking to 200')
#we can seek from the end of the fileslice or from current fileslice
#seek position
#let's seek to fifth byte from the end of the file. that is byte 95
fileslice.seek(-5, 2)
This library also works in writable files. Multiple threads can be used to read
and write to different file slices from the same file. Just make sure you do not
use the original opened file or the fileslices (and the original file object)
will be confused.
--------
Tutorial
--------
Check out fileslice tutorial at http://fileslice.readthedocs.io/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fileslice-0.0.1.tar.gz
(7.7 kB
view details)
File details
Details for the file fileslice-0.0.1.tar.gz
.
File metadata
- Download URL: fileslice-0.0.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d470cc4f8feee66f12b9cf0fd4e656cd7ca72077b2e4c3c0f672751cbdd92bcd |
|
MD5 | 6c51b0801f9f9717175200f7b172745f |
|
BLAKE2b-256 | 2b346c900ee5eba39fb38e95e78a71f797017e05794a4b634d6225015c2822c8 |