~hww3/caudium

ref: 93d5a75fba08db71b832716377276978cdd7888d caudium/tools/uncompress.pike -rwxr-xr-x 1.2 KiB
93d5a75fWilliam Welliver storage: method "None" was missing stop function. should fix error on shutdown 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!bin/pike

object open(string f, string m)
{
  object fd = files.file();
  if(fd->open(f,m)) return fd;
  return 0;
}

void main(int args, array (string) files)
{
  program cl;
  string method;

  while(sscanf(files[0], "%*s/%s", files[0])==2);
  switch(files[0][0])
  {
   case 'd':
   case 'u':
    cl = Gz.inflate;
    method="Uncompress";
    break;
   default:
    cl = Gz.deflate;
    method="Compress";
  }
  
  files = files[1..];

  foreach(files, string file)
  {
    object o = open(file, "r");
    if(o)
    {
      mixed nf;
      nf = cl();
      if(nf->inflate) nf = nf->inflate;
      else if(nf->deflate) nf = nf->deflate;
      string comp;
      write(file+": ");
      string d = o->read();
      write(" Original "+strlen(d)+" ... ");
      if(catch {
	comp = nf(d);
	write(method+"ed: "+strlen(comp)+" ("+
	      ((strlen(comp)*100)/strlen(d))+"%)... ");
      })
      {
	write("Failed to "+method+".\n");
	o->close();
	continue;
      }
      o->close();
      if(!(o = open(file,"wct")))
      {
	write("Failed to open outdata-file.\n");
	o->close();
	continue;
      }	
      o->write(comp);
      write("Done.\n");
    } else
      write("Failed to open "+file+" for reading.\n");
  }
}