Exemple #1
0
static int lmz_writer_add_mem(lua_State *L) {
  lmz_file_t* zip = luaL_checkudata(L, 1, "miniz_writer");
  const char* path = luaL_checkstring(L, 2);
  size_t size;
  const char* data = luaL_checklstring(L, 3, &size);
  mz_uint flags = luaL_optint(L, 4, 0);
  if (!mz_zip_writer_add_mem(&(zip->archive), path, data, size, flags)) {
    return luaL_error(L, "Failure to add entry to zip");
  }
  return 0;
}
Exemple #2
0
    std::string pak::bin() //const
    {
        std::string result;

        if( type == paktype::ZIP )
        {
            mz_zip_archive zip_archive;
            memset( &zip_archive, 0, sizeof(zip_archive) );

            mz_bool status = mz_zip_writer_init_heap( &zip_archive, 0, 128 * 1024 );
            assert( status );
            if( !status )
                return "mz_zip_writer_init_heap() failed!", std::string();

            for( iterator it = this->begin(); it != this->end(); ++it )
            {
                const char *filename = it->operator[]("filename").c_str();
                const char *content = it->operator[]("content").c_str();
                const size_t bufsize = it->operator[]("content").size();

                status = mz_zip_writer_add_mem( &zip_archive, filename, content, bufsize, MZ_DEFAULT_COMPRESSION );
                if( !status )
                    return "mz_zip_writer_add_mem() failed!", std::string();
            }

            void *pBuf;
            size_t pSize;

            status = mz_zip_writer_finalize_heap_archive( &zip_archive, &pBuf, &pSize);
            if( !status )
                return "mz_zip_writer_finalize_heap_archive() failed!", std::string();

            // Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
            // Note for the archive to be valid, it must have been finalized before ending.
            status = mz_zip_writer_end( &zip_archive );
            assert( status );
            if( !status )
                return "mz_zip_writer_end() failed!", std::string();

            result.resize( pSize );
            memcpy( &result.at(0), pBuf, pSize );

            free( pBuf );
        }
        else
        {}

        return result;
    }
Exemple #3
0
	bool ZipIO::addDirectory(const std::string &Name) {
		if (!_kisopen || !_kready || _kmode != OpenMode::WRITE || Name.empty())
			return false;

		return mz_zip_writer_add_mem(&_kzarchive, Name.c_str(), 0, 0, 0);
	}
Exemple #4
0
bool ZipWriter::addDirectory(const Path &dst)
{
    return mz_zip_writer_add_mem(&_archive, dst.ensureSeparator().asString().c_str(), nullptr, 0, 0);
}
Exemple #5
0
bool ZipWriter::addFile(const void *src, size_t len, const Path &dst, int compressionLevel)
{
    return mz_zip_writer_add_mem(&_archive, dst.asString().c_str(), src, len, compressionLevel);
}