Exemple #1
0
/**
  Decompresses a Brotli compressed source buffer.

  Extracts decompressed data to its original form.
  If the compressed source data specified by Source is successfully decompressed
  into Destination, then RETURN_SUCCESS is returned.  If the compressed source data
  specified by Source is not in a valid compressed data format,
  then RETURN_INVALID_PARAMETER is returned.

  @param  Source      The source buffer containing the compressed data.
  @param  SourceSize  The size of source buffer.
  @param  Destination The destination buffer to store the decompressed data
  @param  Scratch     A temporary scratch buffer that is used to perform the decompression.
                      This is an optional parameter that may be NULL if the
                      required scratch buffer size is 0.

  @retval EFI_SUCCESS Decompression completed successfully, and
                      the uncompressed buffer is returned in Destination.
  @retval EFI_INVALID_PARAMETER
                      The source buffer specified by Source is corrupted
                      (not in a valid compressed format).
**/
EFI_STATUS
EFIAPI
BrotliUefiDecompress (
  IN CONST VOID *   Source,
  IN UINTN          SourceSize,
  IN OUT VOID *     Destination,
  IN OUT VOID *     Scratch
  )
{
  UINTN          DestSize = 0;
  EFI_STATUS     Status;
  BROTLI_BUFF    BroBuff;
  UINT64         GetSize;
  UINT8          MaxOffset;

  MaxOffset = BROTLI_SCRATCH_MAX;
  GetSize = BrGetDecodedSizeOfBuf((UINT8 *)Source, MaxOffset - BROTLI_INFO_SIZE, MaxOffset);

  BroBuff.Buff     = Scratch;
  BroBuff.BuffSize = (UINTN)GetSize;

  Status = BrotliDecompress(
            (VOID *)((UINT8 *)Source + BROTLI_SCRATCH_MAX),
            SourceSize - BROTLI_SCRATCH_MAX,
            Destination,
            DestSize,
            (VOID *)(&BroBuff)
            );

  return Status;
}
static SquashStatus
squash_brotli_decompress_stream (SquashStream* stream, SquashOperation operation) {
  SquashBrotliStream* s = (SquashBrotliStream*) stream;

  if (!BrotliDecompress (s->in, s->out)) {
    return SQUASH_FAILED;
  }

  return SQUASH_OK;
}