gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/gzip/gunzip.go (about)

     1  // Copyright 2017-2018 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gzip
     6  
     7  import (
     8  	"io"
     9  
    10  	"github.com/klauspost/pgzip"
    11  )
    12  
    13  // Decompress takes gzip compressed input from io.Reader and expands it using pgzip
    14  // to io.Writer. Data is read in blocksize (KB) chunks using upto the number of
    15  // CPU cores specified.
    16  func Decompress(r io.Reader, w io.Writer, blocksize int, processes int) error {
    17  	zr, err := pgzip.NewReaderN(r, blocksize*1024, processes)
    18  	if err != nil {
    19  		return err
    20  	}
    21  
    22  	if _, err := io.Copy(w, zr); err != nil {
    23  		zr.Close()
    24  		return err
    25  	}
    26  
    27  	return zr.Close()
    28  }