C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

décompresser un buffer mémoire

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Slaanesh
Guest





PostPosted: Mon Jun 21, 2004 10:46 pm    Post subject: décompresser un buffer mémoire Reply with quote



Bonjour,

Je voudrais décompresser un buffer compressé avec zlib et je n'y arrive pas
A la base, les données sont stockées dans un fichier. Je les récupère avec
le code suivant :

/* gets file size */
file = fopen(src, "r");
if (!file) {
return (0);
}
fseek(file, 0, SEEK_END);
fileSize = ftell(file);
rewind(file);

/* maps file content into memory */
data = (char *) mmap(0, fileSize, PROT_READ, MAP_SHARED, fileno(file),
0);

fclose(file);


J'effectue ensuite un appel à la fonction decompress de cette façon :

uncomprLen = fileSize * 2;
dest = (unsigned char *) calloc(uncomprLen, sizeof (char));
if (!dest) {
return (0);
}

err = uncompress(dest, &uncomprLen, data, fileSize);
if (err != Z_OK) {
/* error */
switch (err) {
case Z_DATA_ERROR:
fprintf(stderr, "cannot uncompress file (data corrupted)n");
break;
case Z_MEM_ERROR:
fprintf(stderr, "cannot uncompress file (not enough memory)n");
break;
case Z_BUF_ERROR:
fprintf(stderr, "cannot uncompress file (not enough room in the
output buffer)n");
break;
default:
fprintf(stderr, "cannot uncompress file, unknown error code:
%dn", err);
}
return (0);
}
return (1);

Le problème est que je récupère toujours le code Z_DATA_ERROR quelque soit
les données que je lis dans le fichier source (valides ou non)....

Quelqu'un pourrait-il m'aider à comprendre d'où vient le problème ?

Merci d'avance

--
Slaanesh
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.