import (
"encoding/base64"
"compress/gzip"
"bytes"
"os"
"io
)
// content - base64 gzip content
// path - file path to save
func ExtractAndSaveDocumento(content string, path string) error{
// base64 to bytes
data, err := base64.StdEncoding.DecodeString(content)
if err != nil {
return err
}
// reader to unzip
bReader := bytes.NewReader(data)
// unzip bytes
gReader, err := gzip.NewReader(bReader)
if err != nil {
return err
}
defer gReader.Close()
writer, err := os.Create(path)
if err != nil {
return err
}
defer writer.Close()
// save file content
if _, err = io.Copy(writer, gReader); err != nil {
return err
}
return nil
}
"encoding/base64"
"compress/gzip"
"bytes"
"os"
"io
)
// content - base64 gzip content
// path - file path to save
func ExtractAndSaveDocumento(content string, path string) error{
// base64 to bytes
data, err := base64.StdEncoding.DecodeString(content)
if err != nil {
return err
}
// reader to unzip
bReader := bytes.NewReader(data)
// unzip bytes
gReader, err := gzip.NewReader(bReader)
if err != nil {
return err
}
defer gReader.Close()
writer, err := os.Create(path)
if err != nil {
return err
}
defer writer.Close()
// save file content
if _, err = io.Copy(writer, gReader); err != nil {
return err
}
return nil
}