Coder Social home page Coder Social logo

a740g / bin2data Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 482 KB

Binary to DATA converter and library for QB64-PE

Home Page: https://qb64phoenix.com/forum/showthread.php?tid=2228

License: MIT License

BASIC 100.00%
base64 base64-decoding base64-encoding command-line commandline-tool library qb64 qb64-pe qbasic quickbasic

bin2data's Introduction

BIN2DATA

Bin2Data and it's companion library is written in QB64-PE, that allows for the conversion of binary files to Base64 encoded DATA statements. This library not only encodes binary data into Base64, but also allows for the decoding of Base64 encoded data back into its binary form. The data is optionally compressed using Google's Zopfli compression library if it sees any goodness. This means that files that are already compressed, may not go through one more compression and decompression step. The compressed data is compatible with QB64-PE's _DEFLATE$.

Screenshot

With this library, you can easily store binary data within your QB64 programs, making it easier to distribute and maintain the files required for your program to run. The library provides a simple API that you can use to perform encoding and decoding operations with just a few lines of code.

FEATURES

  • Encode binary files to Base64 encoded DATA statements.
  • Decode Base64 encoded data back into binary form.
  • Simple API that makes it easy to use.

USAGE

  • Clone the repository to a directory of your choice
  • Open Terminal and change to the directory using an appropriate OS command
  • Run git submodule update --init --recursive to initialize, fetch and checkout git submodules
  • Open Bin2Data.bas in the QB64-PE IDE and press F5 to compile and run
  • To use the library in your project add the Toolbox64 repositiory as a Git submodule
  • Then, simply include the library files in your QB64 program and call the relevant functions to perform encoding and decoding operations.

Assuming the a file has been encoded using Bin2Data, here's an example of how you can use the library to to decode Base64 encoded data.

' In this example we used Bin2Data on my_music.mp3 and it created a file called my_music.mp3.bi
' It assumes that you have cloned the Toolbox64 repo in the include subdirectory under your project directory

' First include the Base64 header file
'$INCLUDE:'include/Base64.bi'

' This label is from my_music_mp3.bi
RESTORE data_my_music_mp3_8192

' This loads the encoded & compressed data from the DATA statements after the label above
DIM buffer AS STRING: buffer = Base64_LoadResourceData 

' Now do something with buffer
...

' Include the my_music.mp3.bi before your FUNCTIONs and SUBs
'$INCLUDE:'my_music_mp3.bi'

' OR

' Place contents of my_music_mp3.bi before your FUNCTIONs and SUBs
data_my_music_mp3_8192:
DATA 8192,9877,0
DATA ...

' Finally, don't forget to include the Base64 module file
'$INCLUDE:'include/Base64.bas'

API

FUNCTION Base64_Encode$ (s AS STRING)
FUNCTION Base64_Decode$ (s AS STRING)
FUNCTION Base64_LoadResourceString$ (src AS STRING, ogSize AS _UNSIGNED LONG, isComp AS _BYTE)
FUNCTION Base64_LoadResourceData$

NOTES

  • This requires the latest version of QB64-PE
  • When you clone a repository that contains submodules, the submodules are not automatically cloned by default
  • You will need to use the git submodule update --init --recursive to initialize, fetch and checkout git submodules

ASSETS

bin2data's People

Contributors

a740g avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

dualbrain

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.