Compress-unLZMA

 view release on metacpan or  search on metacpan

unLZMA.xs  view on Meta::CPAN

      return 1;
    }
  }

    New(0, pIn, 1, Content);

  pIn->size = length - 13;
    New(0, pIn->content, pIn->size, char);
  if (pIn->content == 0)
  {
    sprintf(rs + strlen(rs), "can't allocate");
    Safefree(pIn);
    fclose(inputHandle);
    return 1;
  }
  if (!MyReadFile(inputHandle, pIn->content, pIn->size))
  {
    sprintf(rs + strlen(rs), "can't read");
    Safefree(pIn->content);
    Safefree(pIn);
    fclose(inputHandle);
    return 1;
  }

  fclose(inputHandle);

  if (properties[0] >= (9*5*5))
  {
    sprintf(rs + strlen(rs), "Properties error");
    Safefree(pIn->content);
    Safefree(pIn);
    return 1;
  }

  /* empty file: no need to uncompress data */
  if (pOut->size == (unsigned long)0)
  {
    Safefree(pIn->content);
    Safefree(pIn);
    return 0;
  }

  ret = LzmaUncompressData(pIn, pOut, properties, rs);

    Safefree(pIn->content);
    Safefree(pIn);

  return ret;
}

MODULE = Compress::unLZMA		PACKAGE = Compress::unLZMA		

PROTOTYPES: DISABLE

void
uncompressdata(content, size, sizeout, properties)
	char *content
	unsigned int size
	unsigned int sizeout
	unsigned char *properties
PPCODE:
	char sz[800] = { 0 };
	Content *pIn, *pOut;
	int code = 0;
	SV *errsv;

        New(0, pIn, 1, Content);
	pIn->content = content;
	pIn->size = size;

        New(0, pOut, 1, Content);
	pOut->content = NULL;
	pOut->size = sizeout;

	code = LzmaUncompressData(pIn, pOut, properties, sz);

	errsv = get_sv("@", TRUE);

	/* Error */
	if (code)
	{
		sv_setpv(errsv, sz);
		Safefree(pIn->content);
		Safefree(pIn);
		Safefree(pOut->content);
		Safefree(pOut);
		XSRETURN_UNDEF;
	}

	sv_setpv(errsv, "");
	XPUSHs(sv_2mortal(newSVpvn(pOut->content, pOut->size)));
	Safefree(pIn);
	Safefree(pOut->content);
	Safefree(pOut);
	XSRETURN(1);

void
uncompressfile(filename)
	char *filename
PPCODE:
	char sz[800] = { 0 };
	int code = 0;
	unsigned int size = 0;
	Content *pContent;
	SV *errsv;

        New(0, pContent, 1, Content);
	pContent->content = NULL;
	pContent->size = 0;

	code = LzmaUncompressFile(filename, pContent, sz);

	errsv = get_sv("@", TRUE);

	/* Error */
	if (code)
	{
		sv_setpv(errsv, sz);
		Safefree(pContent->content);
		Safefree(pContent);
		XSRETURN_UNDEF;
	}

	sv_setpv(errsv, "");
        if (pContent->size) {
 		XPUSHs(sv_2mortal(newSVpvn(pContent->content, pContent->size)));
	} else {
		XPUSHs(sv_2mortal(newSVpvn("", pContent->size))); /* the empty string */
        }
	Safefree(pContent->content);
	Safefree(pContent);
	XSRETURN(1);



( run in 0.426 second using v1.01-cache-2.11-cpan-71847e10f99 )