No project description provided
Project description
ArrowDrive
Special reader for ArrowBit virtual disks.
vDisk extension: .adrv
How to use it
1- Create a Disk object
from adrv import Disk
myDisk = Disk('myDisk', './vDisks', 4 * 1000 ** 3) # Create a 4GB disk.
Parameters:
name: str- The name of the vDisk
path: str- The directory where the vDisk will be created
size: int- the size of the vDisk, in bytes
You just created a new Disk object that points to the given path. If the disk doesn't exist, it will be created with the necessary directories.
Important: The 4GB limit set up isn't pre-allocated and it's only a virtual limit. It can easily be edited with the class attributes (it should be fixed soon)
2- Create a file...
With the PhysicalBridge
The PhysicalBridge is a bridge between your computer's file system and the virtual disk. With it, you can copy a file from your working directory or another on your computer and your removable storage and vice-versa.
from adrv import Disk
from adrv.bridge import PhysicalBridge
myDisk = Disk('myDisk', './vDisks', 4 * 1000 ** 3) # Create a 4GB disk.
bridge = PhysicalBridge(myDisk)
bridge.send('./images/drawing.png', '/drawings')
PhysicalBridge.send() - Parameters:
filePath: str- The file absolute or relative path on your computer
virtualPath: str- The destination of your file in the virtual disk
newName: str(optional) - The new name of the file, default is the last element of thefilePathvalue.
With the VirtualBridge
You can use the VirtualBridge to transfer a file between two disks with only one method.
from adrv import Disk
from adrv.bridge import VirtualBridge
myDisk = Disk('myDisk', './vDisks', 4 * 1000 ** 3) # Create a 4GB disk.
yourDisk = Disk('yourDisk', './vDisks', 4 * 1000 ** 3) # Create another 4GB disk.
vBridge = VirtualBridge(myDisk, yourDisk)
vBridge.cross('/images/drawing.png', '/drawings', rtl = False) # Copy drawing.png on the first disk to the /drawings directory of the second disk
VirtualBridge() - Parameters:
left: Disk- The default sender Disk
right: Disk- The default receiver Disk
VirtualBridge.cross() - Parameters:
targetPath: str- The targeted file path on the sender
finalPath: str- The destination path of the file in the receiver
rtl: bool(optional) - Choose whether the sender/receiver roles are reversed or not. Default option is False
Manually
from adrv import Disk
myDisk = Disk('myDisk', './vDisks', 4 * 1000 ** 3) # Create a 4GB disk.
myDisk.write('/hello/world.txt', 'Hello World', 'w') # You can use it in a variable to see how many bytes have been written
Disk.write() - Parameters:
vPath: str- The file destination on your virtual disk
content: str | bytes- The file content
mode: str'a' or 'w' - Defines whether the file should be overwritten or not
3- Read a file
The only way to read a file is the Disk.read() method:
from adrv import Disk
myDisk = Disk('myDisk', './vDisks', 4 * 1000 ** 3) # Create a 4GB disk.
content = myDisk.read('/hello/world.txt')
The file variable contains a FileResponse with 4 attributes:
content: str | bytes- The file content as you wrote itname: str- The name of the filetimestamp: int- The virtual file creation timesize: int- The size of the file
Disk.read() - Parameters:
vpath: str- Path of the file to read
4- Delete a file
from adrv import Disk
myDisk = Disk('myDisk', './vDisks', 4 * 1000 ** 3) # Create a 4GB disk.
myDisk.delete('/hello/world.txt') # Similary to write(), you can get the amount of bytes removed from the disk
Disk.delete() - Parameters:
vpath: str- Path of the file to deleted
5- Formatting and file system informations
Formatting a Disk is sometimes useful when you have a totally useless file that you want to recycle, or if your disk is broken.
Basic formatting
The basic formatting overwrites a new, completely blank disk on the old one.
Be careful before using it: The whole content of your virtual disk will be wipped out, the system files as well (will be rewritten)
myDisk = Disk('myDisk', './vDisks', 4 * 1000 ** 3) # Create a 4GB disk.
myDisk.format_disc()
Soft formatting
Available in 1.1
What type of formatting to use
| Basic formatting | Soft formatting | |
|---|---|---|
| Data preservation | ❌ | ✅ |
| Guarenteed efficiency* | ✅ | ❌ |
| Generates a new disk if missing | ❌ | ✅ |
| Convert to another fs (i.g. NTFS) | ❌ | ❌ |
| Copy sys files from another vDisk | ❌ | 🕗 1.1 |
* A guaranteed efficiency means the disk doesn't have any chance to be broken after being formatted.
According to the table above, the two types of formatting have their own advantages. The basic formatting is recommended in the case you would like to wipe all the content of your disk to make a better one. The soft formatting can be used to create a new disk from a simple ZIP archive.
Disk status
You can check the status of the disk with a built-in method, and choose whether you want to use it in your code or visually (i.g. for testing)
from adrv import Disk, convert
disk = Disk('myDisk', './disks', convert(4, 'GB'))
disk.format_disk()
disk.diagnosis() # Prints the result (it should be good)
if not disk.diagnosis(snooze = True).result(): # Snooze prevents the method from printing
print("Your disk is broken")
with open(disk.path, 'w') as file:
file.write('abc')
disk.diagnosis() # Prints the result again (it should be bad)
Response:
This method returns a DiagnoseResponse with the three following items:
disk_format- Returns whether the file targeted by the Disk is correct or not (it should always be True except if the first formatting failed)is_supported- Returns whether the disk is supported by your version of ADRVprimary_files- Returns if the necessary system files are in your disk or not (often related withis_supported)result()- Returns True if all of the above items are True
Note: After a formatting, you have no need to diagnose the disk (it is done automatically)
Other methods
extract_all(target: str):
Extracts the archive in the given directory (target)
f_list(include_ts: bool = False):
List all the files (list[str]) and include their timestamp (list[dict]) if include_ts is True.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adrv-1.3.0.tar.gz.
File metadata
- Download URL: adrv-1.3.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e79198c71f11fd4f15dfe3c4c5a188841fb88efe90b7b6bafac92965ca689f9
|
|
| MD5 |
e98e7a999d3a7bdbf9192cf0b8aa9d18
|
|
| BLAKE2b-256 |
8f22b4256bb177a4eef1538d378145a9d5e066b50041abb373b15d20fe54e38b
|
File details
Details for the file adrv-1.3.0-py3-none-any.whl.
File metadata
- Download URL: adrv-1.3.0-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e44794590be29422936af1e4fd23cff4c7766371f067570dcefbe975f333b26f
|
|
| MD5 |
66bbd13b38822daeb6c366e1400f1a30
|
|
| BLAKE2b-256 |
5c4494f78262e665ec43e1d483b1085ab3294407f640e2cd95a8a5668d5cc280
|