OpenShot Library | OpenShotAudio  0.2.1
juce_GZIPDecompressorInputStream.h
1 
2 /** @weakgroup juce_core-zip
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  This stream will decompress a source-stream using zlib.
33 
34  Tip: if you're reading lots of small items from one of these streams, you
35  can increase the performance enormously by passing it through a
36  BufferedInputStream, so that it has to read larger blocks less often.
37 
38  @see GZIPCompressorOutputStream
39 
40  @tags{Core}
41 */
43 {
44 public:
45  enum Format
46  {
47  zlibFormat = 0,
48  deflateFormat,
49  gzipFormat
50  };
51 
52  //==============================================================================
53  /** Creates a decompressor stream.
54 
55  @param sourceStream the stream to read from
56  @param deleteSourceWhenDestroyed whether or not to delete the source stream
57  when this object is destroyed
58  @param sourceFormat can be used to select which of the supported
59  formats the data is expected to be in
60  @param uncompressedStreamLength if the creator knows the length that the
61  uncompressed stream will be, then it can supply this
62  value, which will be returned by getTotalLength()
63  */
65  bool deleteSourceWhenDestroyed,
66  Format sourceFormat = zlibFormat,
67  int64 uncompressedStreamLength = -1);
68 
69  /** Creates a decompressor stream.
70 
71  @param sourceStream the stream to read from - the source stream must not be
72  deleted until this object has been destroyed
73  */
75 
76  /** Destructor. */
77  ~GZIPDecompressorInputStream() override;
78 
79  //==============================================================================
80  int64 getPosition() override;
81  bool setPosition (int64 pos) override;
82  int64 getTotalLength() override;
83  bool isExhausted() override;
84  int read (void* destBuffer, int maxBytesToRead) override;
85 
86 private:
87  //==============================================================================
89  const int64 uncompressedStreamLength;
90  const Format format;
91  bool isEof = false;
92  int activeBufferSize = 0;
93  int64 originalSourcePos, currentPos = 0;
94  HeapBlock<uint8> buffer;
95 
97  std::unique_ptr<GZIPDecompressHelper> helper;
98 
99  #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
100  // The arguments to this method have changed! Please pass a Format enum instead of the old dontWrap bool.
101  GZIPDecompressorInputStream (InputStream*, bool, bool, int64 x = -1);
102  #endif
103 
104  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GZIPDecompressorInputStream)
105 };
106 
107 } // namespace juce
108 
109 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
The base class for streams that read data.
Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope...
This stream will decompress a source-stream using zlib.