snappy-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +77 -0
  4. data/Rakefile +12 -0
  5. data/ext/snappy/extconf.rb +83 -0
  6. data/ext/snappy/snappy-src/AUTHORS +1 -0
  7. data/ext/snappy/snappy-src/BUILD.bazel +211 -0
  8. data/ext/snappy/snappy-src/CMakeLists.txt +467 -0
  9. data/ext/snappy/snappy-src/CONTRIBUTING.md +31 -0
  10. data/ext/snappy/snappy-src/COPYING +54 -0
  11. data/ext/snappy/snappy-src/MODULE.bazel +23 -0
  12. data/ext/snappy/snappy-src/NEWS +215 -0
  13. data/ext/snappy/snappy-src/README.md +165 -0
  14. data/ext/snappy/snappy-src/WORKSPACE +27 -0
  15. data/ext/snappy/snappy-src/WORKSPACE.bzlmod +0 -0
  16. data/ext/snappy/snappy-src/cmake/SnappyConfig.cmake.in +33 -0
  17. data/ext/snappy/snappy-src/cmake/config.h.in +75 -0
  18. data/ext/snappy/snappy-src/config.h +78 -0
  19. data/ext/snappy/snappy-src/docs/README.md +72 -0
  20. data/ext/snappy/snappy-src/format_description.txt +110 -0
  21. data/ext/snappy/snappy-src/framing_format.txt +135 -0
  22. data/ext/snappy/snappy-src/snappy-c.cc +90 -0
  23. data/ext/snappy/snappy-src/snappy-c.h +138 -0
  24. data/ext/snappy/snappy-src/snappy-internal.h +444 -0
  25. data/ext/snappy/snappy-src/snappy-sinksource.cc +121 -0
  26. data/ext/snappy/snappy-src/snappy-sinksource.h +182 -0
  27. data/ext/snappy/snappy-src/snappy-stubs-internal.cc +42 -0
  28. data/ext/snappy/snappy-src/snappy-stubs-internal.h +531 -0
  29. data/ext/snappy/snappy-src/snappy-stubs-public.h +60 -0
  30. data/ext/snappy/snappy-src/snappy-stubs-public.h.in +63 -0
  31. data/ext/snappy/snappy-src/snappy-test.cc +503 -0
  32. data/ext/snappy/snappy-src/snappy-test.h +342 -0
  33. data/ext/snappy/snappy-src/snappy.cc +2666 -0
  34. data/ext/snappy/snappy-src/snappy.h +257 -0
  35. data/ext/snappy/snappy-src/snappy_test_data.cc +57 -0
  36. data/ext/snappy/snappy-src/snappy_test_data.h +68 -0
  37. data/ext/snappy/snappy-src/snappy_test_tool.cc +471 -0
  38. data/ext/snappy/snappy-src/snappy_unittest.cc +1023 -0
  39. data/ext/snappy/snappy.c +282 -0
  40. data/lib/snappy/snappy.so +0 -0
  41. data/lib/snappy.rb +5 -0
  42. metadata +142 -0
@@ -0,0 +1,257 @@
1
+ // Copyright 2005 and onwards Google Inc.
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are
5
+ // met:
6
+ //
7
+ // * Redistributions of source code must retain the above copyright
8
+ // notice, this list of conditions and the following disclaimer.
9
+ // * Redistributions in binary form must reproduce the above
10
+ // copyright notice, this list of conditions and the following disclaimer
11
+ // in the documentation and/or other materials provided with the
12
+ // distribution.
13
+ // * Neither the name of Google Inc. nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ //
29
+ // A light-weight compression algorithm. It is designed for speed of
30
+ // compression and decompression, rather than for the utmost in space
31
+ // savings.
32
+ //
33
+ // For getting better compression ratios when you are compressing data
34
+ // with long repeated sequences or compressing data that is similar to
35
+ // other data, while still compressing fast, you might look at first
36
+ // using BMDiff and then compressing the output of BMDiff with
37
+ // Snappy.
38
+
39
+ #ifndef THIRD_PARTY_SNAPPY_SNAPPY_H__
40
+ #define THIRD_PARTY_SNAPPY_SNAPPY_H__
41
+
42
+ #include <stddef.h>
43
+ #include <stdint.h>
44
+
45
+ #include <string>
46
+
47
+ #include "snappy-stubs-public.h"
48
+
49
+ namespace snappy {
50
+ class Source;
51
+ class Sink;
52
+
53
+ struct CompressionOptions {
54
+ // Compression level.
55
+ // Level 1 is the fastest
56
+ // Level 2 is a little slower but provides better compression. Level 2 is
57
+ // **EXPERIMENTAL** for the time being. It might happen that we decide to
58
+ // fall back to level 1 in the future.
59
+ // Levels 3+ are currently not supported. We plan to support levels up to
60
+ // 9 in the future.
61
+ // If you played with other compression algorithms, level 1 is equivalent to
62
+ // fast mode (level 1) of LZ4, level 2 is equivalent to LZ4's level 2 mode
63
+ // and compresses somewhere around zstd:-3 and zstd:-2 but generally with
64
+ // faster decompression speeds than snappy:1 and zstd:-3.
65
+ int level = DefaultCompressionLevel();
66
+
67
+ constexpr CompressionOptions() = default;
68
+ constexpr CompressionOptions(int compression_level)
69
+ : level(compression_level) {}
70
+ static constexpr int MinCompressionLevel() { return 1; }
71
+ static constexpr int MaxCompressionLevel() { return 2; }
72
+ static constexpr int DefaultCompressionLevel() { return 1; }
73
+ };
74
+
75
+ // ------------------------------------------------------------------------
76
+ // Generic compression/decompression routines.
77
+ // ------------------------------------------------------------------------
78
+
79
+ // Compress the bytes read from "*reader" and append to "*writer". Return the
80
+ // number of bytes written.
81
+ // First version is to preserve ABI.
82
+ size_t Compress(Source* reader, Sink* writer);
83
+ size_t Compress(Source* reader, Sink* writer,
84
+ CompressionOptions options);
85
+
86
+ // Find the uncompressed length of the given stream, as given by the header.
87
+ // Note that the true length could deviate from this; the stream could e.g.
88
+ // be truncated.
89
+ //
90
+ // Also note that this leaves "*source" in a state that is unsuitable for
91
+ // further operations, such as RawUncompress(). You will need to rewind
92
+ // or recreate the source yourself before attempting any further calls.
93
+ bool GetUncompressedLength(Source* source, uint32_t* result);
94
+
95
+ // ------------------------------------------------------------------------
96
+ // Higher-level string based routines (should be sufficient for most users)
97
+ // ------------------------------------------------------------------------
98
+
99
+ // Sets "*compressed" to the compressed version of "input[0..input_length-1]".
100
+ // Original contents of *compressed are lost.
101
+ //
102
+ // REQUIRES: "input[]" is not an alias of "*compressed".
103
+ // First version is to preserve ABI.
104
+ size_t Compress(const char* input, size_t input_length,
105
+ std::string* compressed);
106
+ size_t Compress(const char* input, size_t input_length,
107
+ std::string* compressed, CompressionOptions options);
108
+
109
+ // Same as `Compress` above but taking an `iovec` array as input. Note that
110
+ // this function preprocesses the inputs to compute the sum of
111
+ // `iov[0..iov_cnt-1].iov_len` before reading. To avoid this, use
112
+ // `RawCompressFromIOVec` below.
113
+ // First version is to preserve ABI.
114
+ size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
115
+ std::string* compressed);
116
+ size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
117
+ std::string* compressed,
118
+ CompressionOptions options);
119
+
120
+ // Decompresses "compressed[0..compressed_length-1]" to "*uncompressed".
121
+ // Original contents of "*uncompressed" are lost.
122
+ //
123
+ // REQUIRES: "compressed[]" is not an alias of "*uncompressed".
124
+ //
125
+ // returns false if the message is corrupted and could not be decompressed
126
+ bool Uncompress(const char* compressed, size_t compressed_length,
127
+ std::string* uncompressed);
128
+
129
+ // Decompresses "compressed" to "*uncompressed".
130
+ //
131
+ // returns false if the message is corrupted and could not be decompressed
132
+ bool Uncompress(Source* compressed, Sink* uncompressed);
133
+
134
+ // This routine uncompresses as much of the "compressed" as possible
135
+ // into sink. It returns the number of valid bytes added to sink
136
+ // (extra invalid bytes may have been added due to errors; the caller
137
+ // should ignore those). The emitted data typically has length
138
+ // GetUncompressedLength(), but may be shorter if an error is
139
+ // encountered.
140
+ size_t UncompressAsMuchAsPossible(Source* compressed, Sink* uncompressed);
141
+
142
+ // ------------------------------------------------------------------------
143
+ // Lower-level character array based routines. May be useful for
144
+ // efficiency reasons in certain circumstances.
145
+ // ------------------------------------------------------------------------
146
+
147
+ // REQUIRES: "compressed" must point to an area of memory that is at
148
+ // least "MaxCompressedLength(input_length)" bytes in length.
149
+ //
150
+ // Takes the data stored in "input[0..input_length]" and stores
151
+ // it in the array pointed to by "compressed".
152
+ //
153
+ // "*compressed_length" is set to the length of the compressed output.
154
+ //
155
+ // Example:
156
+ // char* output = new char[snappy::MaxCompressedLength(input_length)];
157
+ // size_t output_length;
158
+ // RawCompress(input, input_length, output, &output_length);
159
+ // ... Process(output, output_length) ...
160
+ // delete [] output;
161
+ void RawCompress(const char* input, size_t input_length, char* compressed,
162
+ size_t* compressed_length);
163
+ void RawCompress(const char* input, size_t input_length, char* compressed,
164
+ size_t* compressed_length, CompressionOptions options);
165
+
166
+ // Same as `RawCompress` above but taking an `iovec` array as input. Note that
167
+ // `uncompressed_length` is the total number of bytes to be read from the
168
+ // elements of `iov` (_not_ the number of elements in `iov`).
169
+ void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
170
+ char* compressed, size_t* compressed_length);
171
+ void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
172
+ char* compressed, size_t* compressed_length,
173
+ CompressionOptions options);
174
+
175
+ // Given data in "compressed[0..compressed_length-1]" generated by
176
+ // calling the Snappy::Compress routine, this routine
177
+ // stores the uncompressed data to
178
+ // uncompressed[0..GetUncompressedLength(compressed)-1]
179
+ // returns false if the message is corrupted and could not be decrypted
180
+ bool RawUncompress(const char* compressed, size_t compressed_length,
181
+ char* uncompressed);
182
+
183
+ // Given data from the byte source 'compressed' generated by calling
184
+ // the Snappy::Compress routine, this routine stores the uncompressed
185
+ // data to
186
+ // uncompressed[0..GetUncompressedLength(compressed,compressed_length)-1]
187
+ // returns false if the message is corrupted and could not be decrypted
188
+ bool RawUncompress(Source* compressed, char* uncompressed);
189
+
190
+ // Given data in "compressed[0..compressed_length-1]" generated by
191
+ // calling the Snappy::Compress routine, this routine
192
+ // stores the uncompressed data to the iovec "iov". The number of physical
193
+ // buffers in "iov" is given by iov_cnt and their cumulative size
194
+ // must be at least GetUncompressedLength(compressed). The individual buffers
195
+ // in "iov" must not overlap with each other.
196
+ //
197
+ // returns false if the message is corrupted and could not be decrypted
198
+ bool RawUncompressToIOVec(const char* compressed, size_t compressed_length,
199
+ const struct iovec* iov, size_t iov_cnt);
200
+
201
+ // Given data from the byte source 'compressed' generated by calling
202
+ // the Snappy::Compress routine, this routine stores the uncompressed
203
+ // data to the iovec "iov". The number of physical
204
+ // buffers in "iov" is given by iov_cnt and their cumulative size
205
+ // must be at least GetUncompressedLength(compressed). The individual buffers
206
+ // in "iov" must not overlap with each other.
207
+ //
208
+ // returns false if the message is corrupted and could not be decrypted
209
+ bool RawUncompressToIOVec(Source* compressed, const struct iovec* iov,
210
+ size_t iov_cnt);
211
+
212
+ // Returns the maximal size of the compressed representation of
213
+ // input data that is "source_bytes" bytes in length;
214
+ size_t MaxCompressedLength(size_t source_bytes);
215
+
216
+ // REQUIRES: "compressed[]" was produced by RawCompress() or Compress()
217
+ // Returns true and stores the length of the uncompressed data in
218
+ // *result normally. Returns false on parsing error.
219
+ // This operation takes O(1) time.
220
+ bool GetUncompressedLength(const char* compressed, size_t compressed_length,
221
+ size_t* result);
222
+
223
+ // Returns true iff the contents of "compressed[]" can be uncompressed
224
+ // successfully. Does not return the uncompressed data. Takes
225
+ // time proportional to compressed_length, but is usually at least
226
+ // a factor of four faster than actual decompression.
227
+ bool IsValidCompressedBuffer(const char* compressed,
228
+ size_t compressed_length);
229
+
230
+ // Returns true iff the contents of "compressed" can be uncompressed
231
+ // successfully. Does not return the uncompressed data. Takes
232
+ // time proportional to *compressed length, but is usually at least
233
+ // a factor of four faster than actual decompression.
234
+ // On success, consumes all of *compressed. On failure, consumes an
235
+ // unspecified prefix of *compressed.
236
+ bool IsValidCompressed(Source* compressed);
237
+
238
+ // The size of a compression block. Note that many parts of the compression
239
+ // code assumes that kBlockSize <= 65536; in particular, the hash table
240
+ // can only store 16-bit offsets, and EmitCopy() also assumes the offset
241
+ // is 65535 bytes or less. Note also that if you change this, it will
242
+ // affect the framing format (see framing_format.txt).
243
+ //
244
+ // Note that there might be older data around that is compressed with larger
245
+ // block sizes, so the decompression code should not rely on the
246
+ // non-existence of long backreferences.
247
+ static constexpr int kBlockLog = 16;
248
+ static constexpr size_t kBlockSize = 1 << kBlockLog;
249
+
250
+ static constexpr int kMinHashTableBits = 8;
251
+ static constexpr size_t kMinHashTableSize = 1 << kMinHashTableBits;
252
+
253
+ static constexpr int kMaxHashTableBits = 15;
254
+ static constexpr size_t kMaxHashTableSize = 1 << kMaxHashTableBits;
255
+ } // end namespace snappy
256
+
257
+ #endif // THIRD_PARTY_SNAPPY_SNAPPY_H__
@@ -0,0 +1,57 @@
1
+ // Copyright 2020 Google Inc. All Rights Reserved.
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are
5
+ // met:
6
+ //
7
+ // * Redistributions of source code must retain the above copyright
8
+ // notice, this list of conditions and the following disclaimer.
9
+ // * Redistributions in binary form must reproduce the above
10
+ // copyright notice, this list of conditions and the following disclaimer
11
+ // in the documentation and/or other materials provided with the
12
+ // distribution.
13
+ // * Neither the name of Google Inc. nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ //
29
+ // Support code for reading test data.
30
+
31
+ #include "snappy_test_data.h"
32
+
33
+ #include <cstddef>
34
+ #include <cstdlib>
35
+ #include <string>
36
+
37
+ #include "snappy-test.h"
38
+
39
+ namespace snappy {
40
+
41
+ std::string ReadTestDataFile(const char* base, size_t size_limit) {
42
+ std::string srcdir;
43
+ const char* srcdir_env = std::getenv("srcdir"); // This is set by Automake.
44
+ if (srcdir_env) {
45
+ srcdir = std::string(srcdir_env) + "/";
46
+ }
47
+
48
+ std::string contents;
49
+ CHECK_OK(file::GetContents(srcdir + "testdata/" + base, &contents,
50
+ file::Defaults()));
51
+ if (size_limit > 0) {
52
+ contents = contents.substr(0, size_limit);
53
+ }
54
+ return contents;
55
+ }
56
+
57
+ } // namespace snappy
@@ -0,0 +1,68 @@
1
+ // Copyright 2020 Google Inc. All Rights Reserved.
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are
5
+ // met:
6
+ //
7
+ // * Redistributions of source code must retain the above copyright
8
+ // notice, this list of conditions and the following disclaimer.
9
+ // * Redistributions in binary form must reproduce the above
10
+ // copyright notice, this list of conditions and the following disclaimer
11
+ // in the documentation and/or other materials provided with the
12
+ // distribution.
13
+ // * Neither the name of Google Inc. nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ //
29
+ // List of test case files.
30
+
31
+ #ifndef THIRD_PARTY_SNAPPY_SNAPPY_TEST_DATA_H__
32
+ #define THIRD_PARTY_SNAPPY_SNAPPY_TEST_DATA_H__
33
+
34
+ #include <cstddef>
35
+ #include <string>
36
+
37
+ namespace snappy {
38
+
39
+ std::string ReadTestDataFile(const char* base, size_t size_limit);
40
+
41
+ // TODO: Replace anonymous namespace with inline variable when we can
42
+ // rely on C++17.
43
+ namespace {
44
+
45
+ constexpr struct {
46
+ const char* label;
47
+ const char* filename;
48
+ size_t size_limit;
49
+ } kTestDataFiles[] = {
50
+ { "html", "html", 0 },
51
+ { "urls", "urls.10K", 0 },
52
+ { "jpg", "fireworks.jpeg", 0 },
53
+ { "jpg_200", "fireworks.jpeg", 200 },
54
+ { "pdf", "paper-100k.pdf", 0 },
55
+ { "html4", "html_x_4", 0 },
56
+ { "txt1", "alice29.txt", 0 },
57
+ { "txt2", "asyoulik.txt", 0 },
58
+ { "txt3", "lcet10.txt", 0 },
59
+ { "txt4", "plrabn12.txt", 0 },
60
+ { "pb", "geo.protodata", 0 },
61
+ { "gaviota", "kppkn.gtb", 0 },
62
+ };
63
+
64
+ } // namespace
65
+
66
+ } // namespace snappy
67
+
68
+ #endif // THIRD_PARTY_SNAPPY_SNAPPY_TEST_DATA_H__