zipfile

package
v0.0.0-...-c1d82b4 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadAll

func ReadAll(ctx context.Context, zipFile string) (content io.Reader, err error)

ReadAll legge il file zippato passato come parametro e restituisce un io.Reader e un eventuale errore.

func ReadAllGZ

func ReadAllGZ(ctx context.Context, zipFile string) (content []byte, err error)

ReadAllGZ legge il file compresso in gzip passato come parametro e restituisce l'intero contenuto del file e un eventuale errore.

Example
package main

import (
	"bufio"
	"compress/gzip"
	"context"
	"fmt"
	"log"
	"os"

	"github.com/axamon/hermes/zipfile"
)

const data = `
test
test
test
`

func main() {
	testfile := "test.zip"
	flags := os.O_WRONLY | os.O_CREATE | os.O_TRUNC
	file, err := os.OpenFile(testfile, flags, 0644)
	if err != nil {
		log.Fatalf("Failed to open zip for writing: %s", err)
	}

	zippato := gzip.NewWriter(file)

	_, err = zippato.Write([]byte(data))
	zippato.Close()

	ctx := context.TODO()
	content, err := zipfile.ReadAll(ctx, testfile)

	scan := bufio.NewScanner(content)
	for scan.Scan() {
		line := scan.Text()
		fmt.Println(line)
	}
	file.Close()
	err = os.Remove(testfile)
	if err != nil {
		log.Fatalf("Failed to open zip for writing: %s", err)
	}
}
Output:

test
test
test

Types

This section is empty.

Jump to

Keyboard shortcuts

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