TGCode is a simple library that let's you convert binary data into a string and vice-versa.
Project description
tgcode
tgcode is a simple library that let’s you convert binary data into a
string and vice-versa.
This could be useful for sharing files via an IRC channel, send files
via pastebin like services, make you own protocol that uses this
library or anything like that.
Installation
You can install using the pip command line utility.
pip install tgcode
Usage
It’s simple, just use the encode() and decode() functions, just like that:
import tgcode
data = b'Hello, World!'
encoded = tgcode.encode(data)
decoded = tgcode.decode(encoded)
print('Are they equals: {}'.format(decoded==data))
Complex Usage
Okay, okay, you want more information that a snippet? Here we go:
encode()
The encode() encodes a binary value into a decodable
string. It receives as argument the bytes() that will be encoded
and returns the encoded str()
Example:
import tgcode
data = b'Hello, World!' #bytes data to be encoded
encoded_data = tgcode.encode(data) #encodes the data
print('Encoded bytes: {}'.format(encoded_data)) #prints the encoded data
decode()
The decode() function accepts as argument a string returned by
decode() or fast_decode(). It receives as argument the
str() that will be decoded and returns the decoded bytes().
Example:
import tgcode
encoded_data = '_=}o§}v§}v§}y=SG}=}y§}B§}v§}n=H' #the encoded string
data = tgcode.decode(encoded_data) #decodes the string
file = open('tgcode.test', 'wb') #opens a file with "write binary" flag
file.write(data) #writes the decoded data into the file
file.close() #saves the file
fast_encode()
This function splits the data and encodes him in different threads.
The arguments are exactly equals to the encode()’s arguments,
except for the extra thread_quantity argument, that are an integer
(int()) with the amount of threads that will be used. JUST use
this function for binaries biggest than the number of threads, like
files or big messages. The default thread_quantity value are 35.
Example:
import tgcode
file = open('tgcode.test', 'rb') #opens the file with "read binary" flag
data = file.read() #reads the data
fast_encoded = tgcode.fast_encode(data) #fastly encodes the data
file.close() #closes the file
print('Fastly encoded data: {}'.format(fast_encoded)) #prints the encoded data
License
MIT license
Copyright (c) 2016
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \`\`\`notice and
this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
TGCode-0.3.0.post2.zip
(8.7 kB
view details)
File details
Details for the file TGCode-0.3.0.post2.zip
.
File metadata
- Download URL: TGCode-0.3.0.post2.zip
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af37577a24c570d7d34a8e9e2ca628751947abcb918a241d672334536e92cdca |
|
MD5 | d7ac304eafa88bf3fe45d103c81fbc5d |
|
BLAKE2b-256 | 6c88dea0a710fff68c9c9aec32982682018c0795eefb590f553a8ef0dbf2efdf |