...

Source file src/github.com/xi2/xz/dec_xz.go

Documentation: github.com/xi2/xz

     1  /*
     2   * XZ decompressor
     3   *
     4   * Authors: Lasse Collin <lasse.collin@tukaani.org>
     5   *          Igor Pavlov <http://7-zip.org/>
     6   *
     7   * Translation to Go: Michael Cross <https://github.com/xi2>
     8   *
     9   * This file has been put into the public domain.
    10   * You can do whatever you want with this file.
    11   */
    12  
    13  package xz
    14  
    15  /* from linux/include/linux/xz.h **************************************/
    16  
    17  /**
    18   * xzRet - Return codes
    19   * @xzOK:                   Everything is OK so far. More input or more
    20   *                          output space is required to continue.
    21   * @xzStreamEnd:            Operation finished successfully.
    22   * @xzUnSupportedCheck:     Integrity check type is not supported. Decoding
    23   *                          is still possible by simply calling xzDecRun
    24   *                          again.
    25   * @xzMemlimitError:        A bigger LZMA2 dictionary would be needed than
    26   *                          allowed by the dictMax argument given to
    27   *                          xzDecInit.
    28   * @xzFormatError:          File format was not recognized (wrong magic
    29   *                          bytes).
    30   * @xzOptionsError:         This implementation doesn't support the requested
    31   *                          compression options. In the decoder this means
    32   *                          that the header CRC32 matches, but the header
    33   *                          itself specifies something that we don't support.
    34   * @xzDataError:            Compressed data is corrupt.
    35   * @xzBufError:             Cannot make any progress.
    36   *
    37   * xzBufError is returned when two consecutive calls to XZ code cannot
    38   * consume any input and cannot produce any new output.  This happens
    39   * when there is no new input available, or the output buffer is full
    40   * while at least one output byte is still pending. Assuming your code
    41   * is not buggy, you can get this error only when decoding a
    42   * compressed stream that is truncated or otherwise corrupt.
    43   */
    44  type xzRet int
    45  
    46  const (
    47  	xzOK xzRet = iota
    48  	xzStreamEnd
    49  	xzUnsupportedCheck
    50  	xzMemlimitError
    51  	xzFormatError
    52  	xzOptionsError
    53  	xzDataError
    54  	xzBufError
    55  )
    56  
    57  /**
    58   * xzBuf - Passing input and output buffers to XZ code
    59   * @in:         Input buffer.
    60   * @inPos:      Current position in the input buffer. This must not exceed
    61   *              input buffer size.
    62   * @out:        Output buffer.
    63   * @outPos:     Current position in the output buffer. This must not exceed
    64   *              output buffer size.
    65   *
    66   * Only the contents of the output buffer from out[outPos] onward, and
    67   * the variables inPos and outPos are modified by the XZ code.
    68   */
    69  type xzBuf struct {
    70  	in     []byte
    71  	inPos  int
    72  	out    []byte
    73  	outPos int
    74  }
    75  
    76  /* All XZ filter IDs */
    77  type xzFilterID int64
    78  
    79  const (
    80  	idDelta       xzFilterID = 0x03
    81  	idBCJX86      xzFilterID = 0x04
    82  	idBCJPowerPC  xzFilterID = 0x05
    83  	idBCJIA64     xzFilterID = 0x06
    84  	idBCJARM      xzFilterID = 0x07
    85  	idBCJARMThumb xzFilterID = 0x08
    86  	idBCJSPARC    xzFilterID = 0x09
    87  	idLZMA2       xzFilterID = 0x21
    88  )
    89  
    90  // CheckID is the type of the data integrity check in an XZ stream
    91  // calculated from the uncompressed data.
    92  type CheckID int
    93  
    94  func (id CheckID) String() string {
    95  	switch id {
    96  	case CheckNone:
    97  		return "None"
    98  	case CheckCRC32:
    99  		return "CRC32"
   100  	case CheckCRC64:
   101  		return "CRC64"
   102  	case CheckSHA256:
   103  		return "SHA256"
   104  	default:
   105  		return "Unknown"
   106  	}
   107  }
   108  
   109  const (
   110  	CheckNone   CheckID = 0x00
   111  	CheckCRC32  CheckID = 0x01
   112  	CheckCRC64  CheckID = 0x04
   113  	CheckSHA256 CheckID = 0x0A
   114  	checkMax    CheckID = 0x0F
   115  	checkUnset  CheckID = -1
   116  )
   117  
   118  // An XZ stream contains a stream header which holds information about
   119  // the stream. That information is exposed as fields of the
   120  // Reader. Currently it contains only the stream's data integrity
   121  // check type.
   122  type Header struct {
   123  	CheckType CheckID // type of the stream's data integrity check
   124  }
   125  

View as plain text