A simple, efficient utility for converting files to Unicode base64-encoded data URIs.
Project description
file-to-unicode-base64-data-uri
A simple, efficient utility for converting files to Unicode base64-encoded data URIs.
Features
- 📄 Auto-detects the MIME type.
- ♻️ Streaming/generator interface so your program never loads the file fully into memory except for the output string.
- ✅ Python 2 and 3 compatible.
Install
pip install file-to-unicode-base64-data-uri
Usage
# coding=utf-8
from __future__ import print_function
from codecs import open
from file_to_unicode_base64_data_uri import file_to_unicode_base64_data_uri
# Get a single string (data URI)
data_url = file_to_unicode_base64_data_uri('example.png')
print(data_url[:80] + u'...')
# Stream out in chunks (memory efficient for huge files)
from file_to_unicode_base64_data_uri import unicode_base64_data_uri_fragments_generator
with open('output.txt', 'w', 'utf-8') as out:
for fragment in unicode_base64_data_uri_fragments_generator('large_video.mp4'):
out.write(fragment)
Why?
Many libraries read the entire file into memory before encoding or require third-party dependencies. This utility is pure Python, efficient, and works everywhere, even for large files.
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
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
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 file_to_unicode_base64_data_uri-0.1.0a1.tar.gz.
File metadata
- Download URL: file_to_unicode_base64_data_uri-0.1.0a1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d1c705a667d89260da1903c46297ebb542840fca9f8de6cf7f3598b440ab12a
|
|
| MD5 |
3c15b427ae31ce938a3cc68e3b73fca6
|
|
| BLAKE2b-256 |
75130801e20f983dff78fac0ef6c347f65a20a3e55608abb4747413f0dbc995e
|
File details
Details for the file file_to_unicode_base64_data_uri-0.1.0a1-py2.py3-none-any.whl.
File metadata
- Download URL: file_to_unicode_base64_data_uri-0.1.0a1-py2.py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c2da103ac2e2492a0dfb6d5272a12e551fea0eac10d02efc1c9a227671fb057
|
|
| MD5 |
964e7a512dcd9720f993d92047012552
|
|
| BLAKE2b-256 |
6dfd1da221cfcbc8ab0e78e48e5bc83c6a373bc77c85f36cba4112780c57321c
|