snappy / cbits / hs_snappy.cpp

#include "hs_snappy.h"
#include "snappy.h"
#include "snappy-sinksource.h"

using namespace snappy;

size_t _hsnappy_MaxCompressedLength(size_t n)
  return MaxCompressedLength(n);

void _hsnappy_RawCompress(const char *input, size_t input_length,
			  char *compressed, size_t *compressed_length)
  RawCompress(input, input_length, compressed, compressed_length);

int _hsnappy_GetUncompressedLength(const char *compressed,
				   size_t compressed_length,
				   size_t *result)
  return GetUncompressedLength(compressed, compressed_length, result);

int _hsnappy_RawUncompress(const char *compressed, size_t compressed_length,
			   char *uncompressed)
  return RawUncompress(compressed, compressed_length, uncompressed);

class BSSource : public Source 
  BSSource(BS *chunks, size_t nchunks, size_t left)
    : chunks_(chunks), nchunks_(nchunks), cur_(chunks), left_(left) { }
  size_t Available() const { return left_; }
  const char *Peek(size_t *len) {
    *len = cur_->len;
    return cur_->ptr;

  void Skip(size_t n) {
    left_ -= n;
    while (n >= cur_->len) {
      n -= cur_->len;
    if (n > 0) {
      cur_->len -= n;
      cur_->ptr += n;

  BS *chunks_;
  const int nchunks_;
  BS *cur_;
  size_t left_;
void _hsnappy_CompressChunks(BS *chunks, size_t nchunks, size_t length,
			     char *compressed, size_t *compressed_length)
  BSSource reader(chunks, nchunks, length);
  UncheckedByteArraySink writer(compressed);

  Compress(&reader, &writer);

  *compressed_length = writer.CurrentDestination() - compressed;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.