Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

file_to_unicode_base64_data_uri-0.1.0a1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

file_to_unicode_base64_data_uri-0.1.0a1-py2.py3-none-any.whl (4.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file file_to_unicode_base64_data_uri-0.1.0a1.tar.gz.

File metadata

File hashes

Hashes for file_to_unicode_base64_data_uri-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 1d1c705a667d89260da1903c46297ebb542840fca9f8de6cf7f3598b440ab12a
MD5 3c15b427ae31ce938a3cc68e3b73fca6
BLAKE2b-256 75130801e20f983dff78fac0ef6c347f65a20a3e55608abb4747413f0dbc995e

See more details on using hashes here.

File details

Details for the file file_to_unicode_base64_data_uri-0.1.0a1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for file_to_unicode_base64_data_uri-0.1.0a1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9c2da103ac2e2492a0dfb6d5272a12e551fea0eac10d02efc1c9a227671fb057
MD5 964e7a512dcd9720f993d92047012552
BLAKE2b-256 6dfd1da221cfcbc8ab0e78e48e5bc83c6a373bc77c85f36cba4112780c57321c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page