File: notgzip.k

package info (click to toggle)
kaya 0.4.2-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,448 kB
  • ctags: 1,694
  • sloc: cpp: 9,536; haskell: 7,461; sh: 3,013; yacc: 910; makefile: 816; perl: 90
file content (89 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download | duplicates (9)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
program notgzip; 

import Compress;
import Binary;
import System;
import IO;


Void compressFile(String fn)
{
    cfile = open(fn,[Read]);
    ofile = open(fn+".ez",[Write]);

    IO::putStr(ofile,fn);

    fblocks = [];

    while(!eof(cfile)) {
	push(fblocks,readBlock(cfile, 655350));
    }

    putInt(ofile, size(fblocks));
    putStrLn("Writing "+size(fblocks)+" blocks");
    
    for b in fblocks {
	compressed = compressBinary(b);
	csize = blockSize(compressed);
	putInt(ofile, csize);
	writeBlock(ofile,compressed);
    }

    close(cfile);
    close(ofile);    
}

Void uncompressFile(String fn)
{
    ofile = open(fn,[Read]);
    // Read original name
    onm = getString(ofile);

    cfile = open(onm,[Write]);

    putStrLn("Uncompressing "+onm);

    blocks = getInt(ofile);
    putStrLn("Reading "+blocks+" blocks");

    // Read blocks
    for x in [1..blocks] {
	// Get block length
	chunkLength = getInt(ofile);
	putStrLn("Length "+chunkLength);
	b = readBlock(ofile, chunkLength);

	unb = uncompressBinary(b, 655350);
	writeBlock(cfile, unb);
    }

    close(cfile);
    close(ofile);    
}

Void usage()
{
    putStrLn("notgzip (c) 2005 Edwin Brady");
    putStrLn("----------------------------");
    putStrLn("Usage: notgzip [file] [-c|-u]");
    exit(1);
}

Void main()
{
    args = getArgs();
    if (size(args)<2) {
	usage();
    }

    fn = args[1];

    if (args[2]=="-c") {
	compressFile(fn);
    } else if (args[2]=="-u") {
	uncompressFile(fn);
    }
    else {
	usage();
    }
}