Beispiel #1
0
bool file_archive_perform_mode(const char *path, const char *valid_exts,
      const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
      uint32_t crc32, struct archive_extract_userdata *userdata)
{
   switch (cmode)
   {
      case ARCHIVE_MODE_UNCOMPRESSED:
         if (!filestream_write_file(path, cdata, size))
            goto error;
         break;

      case ARCHIVE_MODE_COMPRESSED:
         {
            int ret = 0;
            file_archive_file_handle_t handle;

            handle.stream        = userdata->context;
            handle.data          = NULL;
            handle.real_checksum = 0;
            handle.backend       = file_archive_get_file_backend(userdata->archive_path);

            if (!handle.backend)
               goto error;

            if (!handle.backend->stream_decompress_data_to_file_init(&handle,
                     cdata, csize, size))
               goto error;

            do
            {
               ret = handle.backend->stream_decompress_data_to_file_iterate(
                     handle.stream);
            }while(ret == 0);

            if (!file_archive_decompress_data_to_file(&handle,
                     ret, path, valid_exts,
                     cdata, csize, size, crc32))
               goto error;
         }
         break;
      default:
         goto error;
   }

   return true;

error:
   return false;
}
Beispiel #2
0
bool file_archive_perform_mode(const char *path, const char *valid_exts,
                               const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
                               uint32_t crc32, void *userdata)
{
    switch (cmode)
    {
    case ZLIB_MODE_UNCOMPRESSED:
        if (!filestream_write_file(path, cdata, size))
            goto error;
        break;

    case ZLIB_MODE_DEFLATE:
    {
        int ret = 0;
        file_archive_file_handle_t handle = {0};
        handle.backend = file_archive_get_default_file_backend();

        if (!handle.backend->stream_decompress_data_to_file_init(&handle,
                cdata, csize, size))
            goto error;

        do {
            ret = handle.backend->stream_decompress_data_to_file_iterate(
                      handle.stream);
        } while(ret == 0);

        if (!file_archive_decompress_data_to_file(&handle,
                ret, path, valid_exts,
                cdata, csize, size, crc32))
            goto error;
    }
    break;
    default:
        goto error;
    }

    return true;

error:
    return false;
}