|
1
|
## -*- tcl -*- |
|
2
|
# # ## ### ##### ######## ############# ##################### |
|
3
|
## Copyright (c) 2008 Mark Janssen. |
|
4
|
# |
|
5
|
# This software is licensed as described in the file LICENSE, which |
|
6
|
# you should have received as part of this distribution. |
|
7
|
# |
|
8
|
# This software consists of voluntary contributions made by many |
|
9
|
# individuals. For exact contribution history, see the revision |
|
10
|
# history and logs, available at http://fossil-scm.hwaci.com/fossil |
|
11
|
# # ## ### ##### ######## ############# ##################### |
|
12
|
|
|
13
|
## Commands for creating and managing fossil blobs. |
|
14
|
|
|
15
|
# # ## ### ##### ######## ############# ##################### |
|
16
|
## Requirements |
|
17
|
|
|
18
|
package require Tcl 8.5 ; # Required runtime. |
|
19
|
package require sqlite3 ; # Fossil database access |
|
20
|
package require snit ; # OO system. |
|
21
|
package require zlib |
|
22
|
|
|
23
|
package provide vc::fossil::blob 1.0 |
|
24
|
|
|
25
|
# # ## ### ##### ######## ############# ##################### |
|
26
|
## |
|
27
|
|
|
28
|
namespace eval ::vc::fossil { |
|
29
|
namespace export blob |
|
30
|
snit::type blob { |
|
31
|
option -data "" |
|
32
|
|
|
33
|
constructor {args} { |
|
34
|
$self configurelist $args |
|
35
|
} |
|
36
|
|
|
37
|
method compress {} { |
|
38
|
set data [$self cget -data] |
|
39
|
set n [string length $data] |
|
40
|
set data [zlib compress $data 9] |
|
41
|
set header [binary format I $n] |
|
42
|
return $header$data |
|
43
|
} |
|
44
|
|
|
45
|
method decompress {} { |
|
46
|
set data [$self cget -data] |
|
47
|
binary scan $data I length |
|
48
|
return [zlib decompress [string range $data 4 end] $length ] |
|
49
|
} |
|
50
|
} |
|
51
|
} |
|
52
|
|
|
53
|
|