embed

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractFile

func ExtractFile(fs *embed.FS, srcPath, dstPath string) error
Example
package main

import (
	embed0 "embed"
	"fmt"
	"io"
	"os"
)

//go:embed testData
var embedBuildBat embed0.FS

func main() {
	outputFilePath := "./output.txt"
	if err := ExtractFile(&embedBuildBat, "testData/hello.txt", outputFilePath); err != nil {
		panic(err)
	}
	if _, err := os.Stat(outputFilePath); os.IsNotExist(err) {
		panic(err)
	}
	defer func() {
		if err := os.Remove(outputFilePath); err != nil {
			panic(err)
		}
	}()
	f, _ := os.Open(outputFilePath)
	defer f.Close()
	dataBytes, _ := io.ReadAll(f)
	fmt.Println(string(dataBytes))

}
Output:

Hello World!

Types

This section is empty.

Jump to

Keyboard shortcuts

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