filepacker

command module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 1 Imported by: 0

README

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>')

Documentation

Overview

Copyright © 2023 NAME HERE <EMAIL ADDRESS>

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL