Simplify compression API by decompressing into a SmallVector rather than a MemoryBuffer
[oota-llvm.git] / include / llvm / Support / Compression.h
1 //===-- llvm/Support/Compression.h ---Compression----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains basic functions for compression/uncompression.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_COMPRESSION_H
15 #define LLVM_SUPPORT_COMPRESSION_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include <memory>
19 #include "llvm/ADT/SmallVector.h"
20
21 namespace llvm {
22
23 class MemoryBuffer;
24 class StringRef;
25
26 namespace zlib {
27
28 enum CompressionLevel {
29   NoCompression,
30   DefaultCompression,
31   BestSpeedCompression,
32   BestSizeCompression
33 };
34
35 enum Status {
36   StatusOK,
37   StatusUnsupported,    // zlib is unavailable
38   StatusOutOfMemory,    // there was not enough memory
39   StatusBufferTooShort, // there was not enough room in the output buffer
40   StatusInvalidArg,     // invalid input parameter
41   StatusInvalidData     // data was corrupted or incomplete
42 };
43
44 bool isAvailable();
45
46 Status compress(StringRef InputBuffer,
47                 std::unique_ptr<MemoryBuffer> &CompressedBuffer,
48                 CompressionLevel Level = DefaultCompression);
49
50 Status uncompress(StringRef InputBuffer,
51                   SmallVectorImpl<char> &UncompressedBuffer,
52                   size_t UncompressedSize);
53
54 uint32_t crc32(StringRef Buffer);
55
56 }  // End of namespace zlib
57
58 } // End of namespace llvm
59
60 #endif
61