You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.go 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2015, Joe Tsai. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE.md file.
  4. // Package compress is a collection of compression libraries.
  5. package compress
  6. import (
  7. "bufio"
  8. "io"
  9. "github.com/dsnet/compress/internal/errors"
  10. )
  11. // The Error interface identifies all compression related errors.
  12. type Error interface {
  13. error
  14. CompressError()
  15. // IsDeprecated reports the use of a deprecated and unsupported feature.
  16. IsDeprecated() bool
  17. // IsCorrupted reports whether the input stream was corrupted.
  18. IsCorrupted() bool
  19. }
  20. var _ Error = errors.Error{}
  21. // ByteReader is an interface accepted by all decompression Readers.
  22. // It guarantees that the decompressor never reads more data than is necessary
  23. // from the underlying io.Reader.
  24. type ByteReader interface {
  25. io.Reader
  26. io.ByteReader
  27. }
  28. var _ ByteReader = (*bufio.Reader)(nil)
  29. // BufferedReader is an interface accepted by all decompression Readers.
  30. // It guarantees that the decompressor never reads more data than is necessary
  31. // from the underlying io.Reader. Since BufferedReader allows a decompressor
  32. // to peek at bytes further along in the stream without advancing the read
  33. // pointer, decompression can experience a significant performance gain when
  34. // provided a reader that satisfies this interface. Thus, a decompressor will
  35. // prefer this interface over ByteReader for performance reasons.
  36. //
  37. // The bufio.Reader satisfies this interface.
  38. type BufferedReader interface {
  39. io.Reader
  40. // Buffered returns the number of bytes currently buffered.
  41. //
  42. // This value becomes invalid following the next Read/Discard operation.
  43. Buffered() int
  44. // Peek returns the next n bytes without advancing the reader.
  45. //
  46. // If Peek returns fewer than n bytes, it also returns an error explaining
  47. // why the peek is short. Peek must support peeking of at least 8 bytes.
  48. // If 0 <= n <= Buffered(), Peek is guaranteed to succeed without reading
  49. // from the underlying io.Reader.
  50. //
  51. // This result becomes invalid following the next Read/Discard operation.
  52. Peek(n int) ([]byte, error)
  53. // Discard skips the next n bytes, returning the number of bytes discarded.
  54. //
  55. // If Discard skips fewer than n bytes, it also returns an error.
  56. // If 0 <= n <= Buffered(), Discard is guaranteed to succeed without reading
  57. // from the underlying io.Reader.
  58. Discard(n int) (int, error)
  59. }
  60. var _ BufferedReader = (*bufio.Reader)(nil)