Fixed various mkespfs bugs

v0.9.0
Jeroen Domburg 10 years ago
parent 664ae3c617
commit f400fc2bb3
  1. 2
      mkespfsimage/espfsformat.h
  2. 16
      mkespfsimage/main.c

@ -26,6 +26,6 @@ typedef struct {
int16_t nameLen; int16_t nameLen;
int32_t fileLenComp; int32_t fileLenComp;
int32_t fileLenDecomp; int32_t fileLenDecomp;
} EspFsHeader; } __attribute__((packed)) EspFsHeader;
#endif #endif

@ -37,11 +37,11 @@ size_t compressHeatshrink(char *in, int insize, char *out, int outsize, int leve
char *inp=in; char *inp=in;
char *outp=out; char *outp=out;
int len; int len;
int ws[]={13, 11, 8, 6, 5}; int ws[]={5, 6, 8, 11, 13};
int ls[]={4, 4, 4, 3, 3}; int ls[]={3, 3, 4, 4, 4};
HSE_poll_res pres; HSE_poll_res pres;
HSE_sink_res sres; HSE_sink_res sres;
size_t r=0; size_t r;
if (level==-1) level=8; if (level==-1) level=8;
level=(level-1)/2; //level is now 0, 1, 2, 3, 4 level=(level-1)/2; //level is now 0, 1, 2, 3, 4
heatshrink_encoder *enc=heatshrink_encoder_alloc(ws[level], ls[level]); heatshrink_encoder *enc=heatshrink_encoder_alloc(ws[level], ls[level]);
@ -49,6 +49,11 @@ size_t compressHeatshrink(char *in, int insize, char *out, int outsize, int leve
perror("allocating mem for heatshrink"); perror("allocating mem for heatshrink");
exit(1); exit(1);
} }
//Save encoder parms as first byte
*outp=(ws[level]<<4)|ls[level];
outp++; outsize--;
r=1;
do { do {
if (insize>0) { if (insize>0) {
sres=heatshrink_encoder_sink(enc, inp, insize, &len); sres=heatshrink_encoder_sink(enc, inp, insize, &len);
@ -98,6 +103,7 @@ int handleFile(int f, char *name, int compression, int level) {
if (csize>size) { if (csize>size) {
//Compressing enbiggened this file. Revert to uncompressed store. //Compressing enbiggened this file. Revert to uncompressed store.
compression=COMPRESS_NONE;
csize=size; csize=size;
cdat=fdat; cdat=fdat;
} }
@ -116,9 +122,9 @@ int handleFile(int f, char *name, int compression, int level) {
write(1, name, nameLen); //ToDo: this can eat up a few bytes after the buffer. write(1, name, nameLen); //ToDo: this can eat up a few bytes after the buffer.
write(1, cdat, csize); write(1, cdat, csize);
//Pad out to 32bit boundary //Pad out to 32bit boundary
while (size&3) { while (csize&3) {
write(1, "\000", 1); write(1, "\000", 1);
size++; csize++;
} }
munmap(fdat, size); munmap(fdat, size);
return (csize*100)/size; return (csize*100)/size;

Loading…
Cancel
Save