Bug 1909163 - make select dropdowns more properly tabspecific, r=emilio
[gecko.git] / xpcom / io / SnappyUncompressInputStream.h
blobc61ec321a912265435beca97e85e1d9c899cd443
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_SnappyUncompressInputStream_h__
8 #define mozilla_SnappyUncompressInputStream_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/UniquePtr.h"
12 #include "nsCOMPtr.h"
13 #include "nsIInputStream.h"
14 #include "nsISupportsImpl.h"
15 #include "SnappyFrameUtils.h"
17 namespace mozilla {
19 class SnappyUncompressInputStream final : public nsIInputStream,
20 protected detail::SnappyFrameUtils {
21 public:
22 // Construct a new blocking stream to uncompress the given base stream. The
23 // base stream must also be blocking. The base stream does not have to be
24 // buffered.
25 explicit SnappyUncompressInputStream(nsIInputStream* aBaseStream);
27 private:
28 virtual ~SnappyUncompressInputStream();
30 // Parse the next chunk of data. This may populate mBuffer and set
31 // mBufferFillSize. This should not be called when mBuffer already
32 // contains data.
33 nsresult ParseNextChunk(uint32_t* aBytesReadOut);
35 // Convenience routine to Read() from the base stream until we get
36 // the given number of bytes or reach EOF.
38 // aBuf - The buffer to write the bytes into.
39 // aCount - Max number of bytes to read. If the stream closes
40 // fewer bytes my be read.
41 // aMinValidCount - A minimum expected number of bytes. If we find
42 // fewer than this many bytes, then return
43 // NS_ERROR_CORRUPTED_CONTENT. If nothing was read due
44 // due to EOF (aBytesReadOut == 0), then NS_OK is returned.
45 // aBytesReadOut - An out parameter indicating how many bytes were read.
46 nsresult ReadAll(char* aBuf, uint32_t aCount, uint32_t aMinValidCount,
47 uint32_t* aBytesReadOut);
49 // Convenience routine to determine how many bytes of uncompressed data
50 // we currently have in our buffer.
51 size_t UncompressedLength() const;
53 nsCOMPtr<nsIInputStream> mBaseStream;
55 // Buffer to hold compressed data. Must copy here since we need a large
56 // flat buffer to run the uncompress process on. Always the same length
57 // of SnappyFrameUtils::MaxCompressedBufferLength(snappy::kBlockSize)
58 // bytes long.
59 mozilla::UniquePtr<char[]> mCompressedBuffer;
61 // Buffer storing the resulting uncompressed data. Exactly snappy::kBlockSize
62 // bytes long.
63 mozilla::UniquePtr<char[]> mUncompressedBuffer;
65 // Number of bytes of uncompressed data in mBuffer.
66 size_t mUncompressedBytes;
68 // Next byte of mBuffer to return in ReadSegments(). Must be less than
69 // mBufferFillSize
70 size_t mNextByte;
72 // Next chunk in the stream that has been parsed during read-ahead.
73 ChunkType mNextChunkType;
75 // Length of next chunk's length that has been determined during read-ahead.
76 size_t mNextChunkDataLength;
78 // The stream must begin with a StreamIdentifier chunk. Are we still
79 // expecting it?
80 bool mNeedFirstStreamIdentifier;
82 public:
83 NS_DECL_THREADSAFE_ISUPPORTS
84 NS_DECL_NSIINPUTSTREAM
87 } // namespace mozilla
89 #endif // mozilla_SnappyUncompressInputStream_h__