예제 #1
0
func testDecompressStream(input []byte, reader io.Reader, T *testing.T) {
	// Stream decompression
	streamUnbro, err := ioutil.ReadAll(dec.NewBrotliReader(reader))
	if err != nil {
		T.Error(err)
	}

	check("Stream decompress", input, streamUnbro, T)
}
예제 #2
0
파일: izip.go 프로젝트: Nelson69/izip
func decompressFile(inFileName string, outFileName string, verbose bool, standardOutput bool) {
	var buffer [1024 * 1024 * 32]byte
	var inFile *os.File
	var err error
	if inFileName != "-" {
		inFile, err = os.Open(inFileName)
		checkError(err)
	} else {
		inFile = os.Stdin
	}

	hashtail := NewHashCatcher()
	hashWriter := NewHashWriter()

	if !readHeader(inFile) {
		fmt.Printf("Invalid header!\n")
		os.Exit(1)
	}

	readerTee := io.TeeReader(inFile, hashtail)

	brotliReader := dec.NewBrotliReader(readerTee)
	defer brotliReader.Close()

	var outFile *os.File
	if !standardOutput {
		outFile, err = os.Create(outFileName)
		checkError(err)
	} else {
		outFile = os.Stdout
	}

	outFileMulti := io.MultiWriter(outFile, hashWriter)

	io.CopyBuffer(outFileMulti, brotliReader, buffer[:])

	outFile.Close()

	hashOutput := hashWriter.Sum()

	if bytes.Compare(hashOutput, hashtail.hashbuffer[:]) == 0 {
		os.Remove(inFileName)
		os.Exit(0)
	} else {
		fmt.Printf("Error decompressing.  Hashes don't match")
		os.Exit(1)
	}
}
예제 #3
0
파일: cbrotli.go 프로젝트: itchio/wharf
func (bc *brotliDecompressor) Apply(reader io.Reader) (io.Reader, error) {
	br := dec.NewBrotliReader(reader)
	return br, nil
}