Skip to content

sebps/filepacker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Filepacker

Package providing a way to pack a full directory of files into a single go file in order to provide access to their content at runtime.

Install

go install github.com/sebps/filepacker@v1.0.1

Pack files

Executing filepacker command will pack a given source directory into a single .go file. All the directory files will be recursively wrapped. Any file will be made further accessible at run time combining a leading character "/" and the path of the file relatively to its initial source directory.

Usage

To pack a directory run the following command :

filepacker pack -s directory -t package -p resources

Generated file

The result of the previous command execution will be a package.go file with the following content :

package resources // package name using flag -p

// Code generated by filepacker; DO NOT EDIT.

var repositoryInstance *repository

func init() {
	repositoryInstance = &repository{
		storage: make(map[string][]byte),
	}
	repositoryInstance.storage["/test.txt"] = []byte{116, 101, 115, 116}
}

type repository struct {
	storage map[string][]byte
}

func (r *repository) Get(filename string) []byte {
	return repositoryInstance.storage[filename]
}

Access files

At runtime, content of the files can be accessed from anywhere using the package getter as follows :

import (
    filepackage "module_name/resources"
) 

var fileBytes []byte := filepackage.Get('/<file_path>')

About

A cli tool to pack a directory into a single .go file

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages