SkFrontBufferedStream.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkFrontBufferedStream_DEFINED
  8. #define SkFrontBufferedStream_DEFINED
  9. #include "SkStream.h"
  10. /**
  11. * Specialized stream that buffers the first X bytes of a stream,
  12. * where X is passed in by the user. Note that unlike some buffered
  13. * stream APIs, once more bytes than can fit in the buffer are read,
  14. * no more buffering is done. This stream is designed for a use case
  15. * where the caller knows that rewind will only be called from within
  16. * X bytes (inclusive), and the wrapped stream is not necessarily
  17. * able to rewind at all.
  18. */
  19. class SK_API SkFrontBufferedStream {
  20. public:
  21. /**
  22. * Creates a new stream that wraps and buffers an SkStream.
  23. * @param stream SkStream to buffer. If stream is NULL, NULL is
  24. * returned. When this call succeeds (i.e. returns non NULL),
  25. * SkFrontBufferedStream is expected to be the only owner of
  26. * stream, so it should no be longer used directly.
  27. * SkFrontBufferedStream will delete stream upon deletion.
  28. * @param minBufferSize Minimum size of buffer required.
  29. * @return An SkStream that can buffer at least minBufferSize, or
  30. * NULL on failure. The caller is required to delete when finished with
  31. * this object.
  32. */
  33. static std::unique_ptr<SkStreamRewindable> Make(std::unique_ptr<SkStream> stream,
  34. size_t minBufferSize);
  35. };
  36. #endif // SkFrontBufferedStream_DEFINED