[Tux4kids-tuxtype-dev] [Tuxmath-devel] Tar-zip library

Akash Gangil akashg1611 at gmail.com
Sun Jul 4 19:15:12 UTC 2010


Hi Jesus,


On Sat, Jul 3, 2010 at 3:59 AM, Jesus Mager <fongog at gmail.com> wrote:

> Hi david (and all)!
>
> Thank you. I want to write code that can read a campaign file for
> tuxhistory. This file should be a compressed file that contains map
> files, lua scripts, etc... Mainly I need a transparent access to this
> files (I don't need inflate the files in a directory) to load the
> content in to memory. I was searching, but cant find any good resource
> to do that with zlib. I found a very good article [1], but it only
> shows a transparent access for one compressed file using zlib. The
> same text illustrates a good way to access multiple files using
> zzip[2]. Even though the library seems to be written in ANSI-C some
> comments specifics multiplaform/cross compiling problems. Any idea to
> deal this issue?
>
> [1] http://www.kekkai.org/roger/sdl/rwops/rwops.html
> [2] http://zziplib.sourceforge.net/
>
> 2010/6/30 David Bruce <davidstuartbruce at gmail.com>:
> > Hi,
> >
> > On Wed, Jun 30, 2010 at 11:40 AM, Jesus Mager <fongog at gmail.com> wrote:
> >> Hi all!
> >>
> >> I'm trying to find a good way to compress and inflate the campaing
> >> files that should contain things like XML files, and in the future LUA
> >> and other text files. I was thinking zlib is a good option
> >
> > I take it you want to save space on the user's HD?  Obviously, our
> > tarballs and installer files are already compressed.
> >
> > Anyway, zlib is definitely cross-platform and is already part of our
> > dependencies (IIRC, SDL_image depends on zlib).  Thus, if it does what
> > needs to be done, you can use it without worrying about having to drag
> > in additional libs.  If that is what you do, we should add a test in
> > configure.ac to directly test for it, just so we still know that it is
> > available even if a future version of SDL_image no longer uses it.
> >
> > Cheers,
> >
> > David
> >
>
>
>
> --
> Jesus Mager
> [www.h1n1-al.blogspot.com]
>
> _______________________________________________
> Tux4kids-tuxtype-dev mailing list
> Tux4kids-tuxtype-dev at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/tux4kids-tuxtype-dev
>


Won't it work if I make two objects similarly instead of one, that's what
they
seem to have done with zziplib.

#include "SDL.h"
#include <stdio.h>
#include <zlib.h>

int main(void) {
  SDL_Surface *screen;
  SDL_Surface *one;
  SDL_Rect rect;

  /* This is the RWops structure we'll be using */
  SDL_RWops *rw;

  /* gzFile is the Zlib equivalent of FILE from stdio */
  gzFile file;

  /* We'll be needing space to store our graphic into.  The penguin
     graphic is about 12k, so we'll fake it for now.  You'd want to
     figure out how much space you need for other graphics in a real
     application, though. */
  Uint8 buffer[13000];

  /* We'll need to store the actual size of the file when it comes in
   */
  int filesize;

  SDL_Init(SDL_INIT_VIDEO);

  atexit(SDL_Quit);

  screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF);

  /* Opens up the file with Zlib */
  file = gzopen("penguin.gz", "r");

  /*Your 2nd compressed file here*/

  file2 = gzopen("number2.gz", "r");

  /* Decompresses the file into memory (the buffer we set aside),
     13000 bytes max.  gzread returns the number of (decompressed)
     bytes it actually read, and we need that information for
     later. */
  filesize = gzread(file, buffer, 13000);

  filesize2 = gzread(file2, buffer, 13000);

/* Gives us an RWops from memory - SDL_RWFromMem needs to know where the
data is, and how big it is (thus why we saved the filesize) */ rw =
SDL_RWFromMem(buffer, filesize);

  rw2 = SDL_RWFromMem(buffer, filesize2);

/* The function that does the loading doesn't change at all */ one =
SDL_LoadBMP_RW(rw, 0);

  two = SDL_LoadBMP_RW(rw2, 0);

/* And clean up */ SDL_FreeRW(rw); gzclose(file); /* Haphazard way of
getting stuff to the screen */ rect.x = rect.y = 20; rect.w = one -> w;
rect.y = one -> h; SDL_BlitSurface(one, NULL, screen, &rect);


  rect.x += rect.w + 10;
  rect.w = two -> w;
  rect.h = two -> h;
  SDL_BlitSurface(two, NULL, screen, &rect);


SDL_Flip(screen); SDL_Delay(3000); }




-- 
Best Regards
Akash Gangil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/tux4kids-tuxtype-dev/attachments/20100705/4fbd9141/attachment.htm>


More information about the Tux4kids-tuxtype-dev mailing list