Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
ArchiveReader Class Reference

#include <archivereader.h>

List of all members.

Public Member Functions

 ArchiveReader ()
 ~ArchiveReader ()
int Open (const char *path)
void Close ()
int ExtractFile (const char *item, const char *destination)

Private Member Functions

int ExtractItemToStream (const MarItem *item, FILE *fp)

Private Attributes

MarFile * mArchive

Detailed Description

Definition at line 46 of file archivereader.h.


Constructor & Destructor Documentation

Definition at line 49 of file archivereader.h.

: mArchive(NULL) {}

Definition at line 50 of file archivereader.h.

{ Close(); }

Here is the call graph for this function:


Member Function Documentation

Definition at line 65 of file archivereader.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int ArchiveReader::ExtractFile ( const char *  item,
const char *  destination 
)

Definition at line 74 of file archivereader.cpp.

{
  const MarItem *item = mar_find_item(mArchive, name);
  if (!item)
    return READ_ERROR;

#ifdef XP_WIN
  int fd = _open(dest, _O_BINARY|_O_CREAT|_O_TRUNC|_O_WRONLY, item->flags);
#else
  int fd = creat(dest, item->flags);
#endif
  if (fd == -1)
    return WRITE_ERROR;

  FILE *fp = fdopen(fd, "wb");
  if (!fp)
    return WRITE_ERROR;

  int rv = ExtractItemToStream(item, fp);

  fclose(fp);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ArchiveReader::ExtractItemToStream ( const MarItem item,
FILE fp 
) [private]

Definition at line 99 of file archivereader.cpp.

{
  /* decompress the data chunk by chunk */

  char inbuf[BUFSIZ], outbuf[BUFSIZ];
  bz_stream strm;
  int offset, inlen, ret = OK;

  memset(&strm, 0, sizeof(strm));
  if (BZ2_bzDecompressInit(&strm, 0, 0) != BZ_OK)
    return UNEXPECTED_ERROR;

  offset = 0;
  for (;;) {
    if (!item->length) {
      ret = UNEXPECTED_ERROR;
      break;
    }

    if (offset < (int) item->length && strm.avail_in == 0) {
      inlen = mar_read(mArchive, item, offset, inbuf, BUFSIZ);
      if (inlen <= 0)
        return READ_ERROR;
      offset += inlen;
      strm.next_in = inbuf;
      strm.avail_in = inlen;
    }

    strm.next_out = outbuf;
    strm.avail_out = BUFSIZ;

    ret = BZ2_bzDecompress(&strm);
    if (ret != BZ_OK && ret != BZ_STREAM_END) {
      ret = UNEXPECTED_ERROR;
      break;
    }

    if (strm.avail_out < BUFSIZ) {
      if (fwrite(outbuf, BUFSIZ - strm.avail_out, 1, fp) != 1) {
        ret = WRITE_ERROR;
        break;
      }
    }

    if (ret == BZ_STREAM_END) {
      ret = OK;
      break;
    }
  }

  BZ2_bzDecompressEnd(&strm);
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ArchiveReader::Open ( const char *  path)

Definition at line 52 of file archivereader.cpp.

{
  if (mArchive)
    Close();

  mArchive = mar_open(path);
  if (!mArchive)
    return READ_ERROR;

  return OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

MarFile* ArchiveReader::mArchive [private]

Definition at line 60 of file archivereader.h.


The documentation for this class was generated from the following files: