File: zlib.tcl

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (100 lines) | stat: -rw-r--r-- 2,603 bytes parent folder | download | duplicates (2)
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
90
91
92
93
94
95
96
97
98
99
100
# -*- tcl -*-
# # ## ### ##### ######## #############
# (C) 2009 Andreas Kupries

# @@ Meta Begin
# Package tcl::transform::zlib 1.0.2
# Meta as::author {Andreas Kupries}
# Meta as::copyright 2009
# Meta as::license BSD
# Meta as::notes   Possibilities for extension: Currently
# Meta as::notes   the mapping between read/write and
# Meta as::notes   de/compression is fixed. Allow it to be
# Meta as::notes   configured at construction time.
# Meta description Implementation of a zlib (de)compressor.
# Meta description Based on Tcl 8.6's transformation
# Meta description reflection support (TIP 230) and zlib
# Meta description support (TIP 234). Compresses on write.
# Meta description Exports a single command adding a new
# Meta description transformation of this type to a channel.
# Meta description Two arguments, the channel to extend,
# Meta description and the compression level. No result.
# Meta platform tcl
# Meta require tcl::transform::core
# Meta require {Tcl 8.6}
# @@ Meta End

# # ## ### ##### ######## #############

package require Tcl 8.6 9
package require tcl::transform::core

# # ## ### ##### ######## #############

namespace eval ::tcl::transform {}

proc ::tcl::transform::zlib {chan {level 4}} {
    ::chan push $chan [zlib::implementation new $level]
    return
}

oo::class create ::tcl::transform::zlib::implementation {
    superclass tcl::transform::core ;# -> initialize, finalize, destructor

    # This transformation is intended for streaming operation. Seeking
    # the channel while it is active may cause undesirable
    # output. Proper behaviour may require the destruction of the
    # transform before seeking.

    method initialize {c mode} {
	set compressor   [zlib stream deflate -level $level]
	set decompressor [zlib stream inflate]

	next $c $mode
    }

    method finalize {c} {
	$compressor   close
	$decompressor close

	next $c
    }

    method write {c data} {
	$compressor put $data
	return [$compressor get]
    }

    method read {c data} {
	$decompressor put $data
	return [$decompressor get]
    }

    method flush {c} {
	$compressor flush
	return [$compressor get]
    }

    method drain {c} {
	$decompressor flush
	return [$decompressor get]
    }

    # # ## ### ##### ######## #############

    constructor {thelevel} {
	# Should validate input (level in (0 ...9))
	set level $thelevel
	return
    }

    # # ## ### ##### ######## #############

    variable level compressor decompressor

    # # ## ### ##### ######## #############
}

# # ## ### ##### ######## #############
package provide tcl::transform::zlib 1.0.2
return