Beispiel #1
0
	deflate_source(source const& src, bool compress, bool pull = true)
	: octet_reader(src)
	, pull(pull)
	, compress(compress)
	{
		str.zalloc = 0;
		str.zfree = 0;
		str.opaque = 0;
		
		if (compress)
			mz_deflateInit(&str, MZ_DEFAULT_COMPRESSION);
		else
			mz_inflateInit(&str);
		
		str.avail_in = 0;
		str.avail_out = 0;

		prepare_out();
	}
Beispiel #2
0
static int lmz_deflator_init(lua_State* L) {
  int level = luaL_optint(L, 1, MZ_DEFAULT_COMPRESSION);
  if (level < MZ_DEFAULT_COMPRESSION || level > MZ_BEST_COMPRESSION) {
    luaL_error(L, "Compression level must be between -1 and 9");
  }
  lmz_stream_t* stream = lua_newuserdata(L, sizeof(*stream));
  mz_streamp miniz_stream = &(stream->stream);
  luaL_getmetatable(L, "miniz_deflator");
  lua_setmetatable(L, -2);
  memset(miniz_stream, 0, sizeof(*miniz_stream));
  int status = mz_deflateInit(miniz_stream, level);
  if (status != MZ_OK) {
    const char* msg = mz_error(status);
    if (msg) {
      luaL_error(L, "Problem initializing stream: %s", msg);
    } else {
      luaL_error(L, "Problem initializing stream");
    }
  }
  stream->mode = 0;
  return 1;
}