Skip to content
/ binfs Public

Library for embedding binary or text files into C++ programs

License

Notifications You must be signed in to change notification settings

bleenco/binfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

binfs

This package converts any file into manageable C++ source code. It is useful for embedding binary or text data into a C++ program.

Installation

To compile and install the library use the following (MacOS & Linux):

git clone https://github.com/bleenco/binfs.git
cd binfs/
make
make install

To compile program on Windows follow this steps (assuming you have CMake installed):

git clone https://github.com/bleenco/binfs.git
cd binfs/
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..
cmake --build . --config Release

Usage

Conversion is done on one or more sets of files. They are all embedded in a new C++ source file.

The simplest invocation generates a binfs.hpp file in the current working directory. It include all files recursively from the data/ directory.

$ binfs data/

To specify the name of the output file being generated, we use the following:

$ binfs -o myfile.hpp data/

Multiple input directories or files can be specified if necessary.

$ binfs data/ data2/ /path/to/image.png /path/to/my_video.mp4

Accessing the asset

To access asset data, we use the binfs->get_file(filepath); function which is included in the generated output.

#include <string>
#include <fstream>
#include "bindata.hpp"

int main()
{
  BinFS::BinFS *binfs = new BinFS::BinFS();
  binfs->init(); // load the files

  std::string txt_file = binfs->get_file("data/CMakeLists.txt");
  std::string video_file = binfs->get_file("/path/to/my_video.mp4");

  // write accessed video data into output file
  std::ofstream output("out.mp4", std::fstream::binary);
  output << video_file;

  return 0;
}

Optional compression

Not yet implemented.

Working with us

We would love to receive community support. Whether fixing bugs or creating new features - we would appreciate it! Please read our guideline for contribution and don't forget to check our issues list.

Credits

This package was heavily inspired by go-bindata library with same purpose but for Go language.

Licence

The MIT License (MIT)

Copyright (c) 2018 Bleenco GmbH https://bleenco.com

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.

About

Library for embedding binary or text files into C++ programs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published