-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from mdouchement/hli
HLI file format
- Loading branch information
Showing
10 changed files
with
271 additions
and
137 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package hli | ||
|
||
import ( | ||
"compress/gzip" | ||
"io" | ||
|
||
"github.com/klauspost/compress/zstd" | ||
) | ||
|
||
type compresserWriter interface { | ||
io.WriteCloser | ||
Flush() error | ||
} | ||
|
||
func newCompresserWriter(w io.Writer, h *Header) (c compresserWriter) { | ||
var err error | ||
|
||
switch h.Compression { | ||
case CompressionGzip: | ||
c = gzip.NewWriter(w) | ||
case CompressionZstd: | ||
c, err = zstd.NewWriter(w) | ||
} | ||
|
||
if err != nil { | ||
panic(err) // Should never occurred | ||
} | ||
|
||
return | ||
} | ||
|
||
func newCompresserReader(r io.Reader, h *Header) (c io.ReadCloser) { | ||
var err error | ||
|
||
switch h.Compression { | ||
case CompressionGzip: | ||
c, err = gzip.NewReader(r) | ||
case CompressionZstd: | ||
c, err = newzstdreader(r) | ||
} | ||
|
||
if err != nil { | ||
panic(err) // Should never occurred | ||
} | ||
|
||
return | ||
} | ||
|
||
type zstdreader struct { | ||
*zstd.Decoder | ||
} | ||
|
||
func newzstdreader(r io.Reader) (*zstdreader, error) { | ||
c, err := zstd.NewReader(r) | ||
return &zstdreader{c}, err | ||
} | ||
|
||
func (r *zstdreader) Close() error { | ||
r.Decoder.Close() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.