diff options
Diffstat (limited to 'src/Codec/Binary/DataEncoding.hs')
-rw-r--r-- | src/Codec/Binary/DataEncoding.hs | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/src/Codec/Binary/DataEncoding.hs b/src/Codec/Binary/DataEncoding.hs new file mode 100644 index 0000000..1be49c8 --- /dev/null +++ b/src/Codec/Binary/DataEncoding.hs | |||
@@ -0,0 +1,174 @@ | |||
1 | -- | | ||
2 | -- Module : Codec.Binary.DataEncoding | ||
3 | -- Copyright : (c) 2007 Magnus Therning | ||
4 | -- License : BSD3 | ||
5 | -- | ||
6 | -- This module exposes several instances of 'DataCodec', one for each data | ||
7 | -- encoding implemented in the library without causing the name clashing that | ||
8 | -- would result from importing the individual encoding modules. | ||
9 | -- | ||
10 | -- Further documentation and information can be found at | ||
11 | -- <http://www.haskell.org/haskellwiki/Library/Data_encoding>. | ||
12 | module Codec.Binary.DataEncoding | ||
13 | ( DataCodec | ||
14 | , base16 | ||
15 | , base32 | ||
16 | , base32Hex | ||
17 | , base64 | ||
18 | , base64Url | ||
19 | , base85 | ||
20 | , chop | ||
21 | , decode | ||
22 | , encode | ||
23 | , py | ||
24 | , qp | ||
25 | , unchop | ||
26 | , url | ||
27 | , uu | ||
28 | , xx | ||
29 | ) | ||
30 | where | ||
31 | |||
32 | import Data.Word | ||
33 | |||
34 | import qualified Codec.Binary.Base16 as Base16 | ||
35 | import qualified Codec.Binary.Base32 as Base32 | ||
36 | import qualified Codec.Binary.Base32Hex as Base32Hex | ||
37 | import qualified Codec.Binary.Base64 as Base64 | ||
38 | import qualified Codec.Binary.Base64Url as Base64Url | ||
39 | import qualified Codec.Binary.Base85 as Base85 | ||
40 | import qualified Codec.Binary.Url as Url | ||
41 | import qualified Codec.Binary.Uu as Uu | ||
42 | import qualified Codec.Binary.Xx as Xx | ||
43 | import qualified Codec.Binary.QuotedPrintable as QP | ||
44 | import qualified Codec.Binary.PythonString as Py | ||
45 | |||
46 | -- {{{1 DataCodec | ||
47 | -- | Used to group a specific data encoding's functions. | ||
48 | data DataCodec = DataCodec { | ||
49 | encode :: [Word8] -> String, | ||
50 | decode :: String -> Maybe [Word8], | ||
51 | chop :: Int -> String -> [String], | ||
52 | unchop :: [String] -> String | ||
53 | } | ||
54 | |||
55 | -- {{{1 base16 | ||
56 | -- | Base16 encoding, see "Codec.Binary.Base16" for more details on | ||
57 | -- the individual functions. | ||
58 | base16 :: DataCodec | ||
59 | base16 = DataCodec { | ||
60 | encode=Base16.encode, | ||
61 | decode=Base16.decode, | ||
62 | chop=Base16.chop, | ||
63 | unchop=Base16.unchop | ||
64 | } | ||
65 | |||
66 | -- {{{1 base32 | ||
67 | -- | Base32 encoding, see "Codec.Binary.Base32" for more details on | ||
68 | -- the individual functions. | ||
69 | base32 :: DataCodec | ||
70 | base32 = DataCodec { | ||
71 | encode=Base32.encode, | ||
72 | decode=Base32.decode, | ||
73 | chop=Base32.chop, | ||
74 | unchop=Base32.unchop | ||
75 | } | ||
76 | |||
77 | -- {{{1 base32Hex | ||
78 | -- | Base32Hex encoding, see "Codec.Binary.Base32Hex" for more details | ||
79 | -- on the individual functions. | ||
80 | base32Hex :: DataCodec | ||
81 | base32Hex = DataCodec { | ||
82 | encode=Base32Hex.encode, | ||
83 | decode=Base32Hex.decode, | ||
84 | chop=Base32Hex.chop, | ||
85 | unchop=Base32Hex.unchop | ||
86 | } | ||
87 | |||
88 | -- {{{1 base64 | ||
89 | -- | Base64 encoding, see "Codec.Binary.Base64" for more details on | ||
90 | -- the individual functions. | ||
91 | base64 :: DataCodec | ||
92 | base64 = DataCodec { | ||
93 | encode=Base64.encode, | ||
94 | decode=Base64.decode, | ||
95 | chop=Base64.chop, | ||
96 | unchop=Base64.unchop | ||
97 | } | ||
98 | |||
99 | -- {{{1 base64Url | ||
100 | -- | Base64Url encoding, see "Codec.Binary.Base64Url" for more details | ||
101 | -- on the individual functions. | ||
102 | base64Url :: DataCodec | ||
103 | base64Url = DataCodec { | ||
104 | encode=Base64Url.encode, | ||
105 | decode=Base64Url.decode, | ||
106 | chop=Base64Url.chop, | ||
107 | unchop=Base64Url.unchop | ||
108 | } | ||
109 | |||
110 | -- {{{1 base85 | ||
111 | -- | Base85 encoding, see "Codec.Binary.Base85" for more details | ||
112 | -- on the individual functions. | ||
113 | base85 :: DataCodec | ||
114 | base85 = DataCodec { | ||
115 | encode=Base85.encode, | ||
116 | decode=Base85.decode, | ||
117 | chop=Base85.chop, | ||
118 | unchop=Base85.unchop | ||
119 | } | ||
120 | |||
121 | -- {{{1 uu | ||
122 | -- | Uuencoding, see "Codec.Binary.Uu" for more details on the | ||
123 | -- individual functions. | ||
124 | uu :: DataCodec | ||
125 | uu = DataCodec { | ||
126 | encode=Uu.encode, | ||
127 | decode=Uu.decode, | ||
128 | chop=Uu.chop, | ||
129 | unchop=Uu.unchop | ||
130 | } | ||
131 | |||
132 | -- {{{1 xx | ||
133 | -- | Xxencoding, see "Codec.Binary.Xx" for more details on the | ||
134 | -- individual functions. | ||
135 | xx :: DataCodec | ||
136 | xx = DataCodec { | ||
137 | encode=Xx.encode, | ||
138 | decode=Xx.decode, | ||
139 | chop=Xx.chop, | ||
140 | unchop=Xx.unchop | ||
141 | } | ||
142 | |||
143 | -- {{{1 quoted-printable | ||
144 | -- | Quoted-printable, see "Codec.Binary.QuotedPrintable" for more details on | ||
145 | -- the individual functions. | ||
146 | qp :: DataCodec | ||
147 | qp = DataCodec | ||
148 | { encode = QP.encode | ||
149 | , decode = QP.decode | ||
150 | , chop = QP.chop | ||
151 | , unchop = QP.unchop | ||
152 | } | ||
153 | |||
154 | -- {{{1 python string | ||
155 | -- | Quoted-printable, see "Codec.Binary.PythonString" for more details on | ||
156 | -- the individual functions. | ||
157 | py :: DataCodec | ||
158 | py = DataCodec | ||
159 | { encode = Py.encode | ||
160 | , decode = Py.decode | ||
161 | , chop = Py.chop | ||
162 | , unchop = Py.unchop | ||
163 | } | ||
164 | |||
165 | -- {{{1 url encoding | ||
166 | -- | URL encoding, see "Codec.Binary.Url" for more details on the individual | ||
167 | -- functions. | ||
168 | url :: DataCodec | ||
169 | url = DataCodec | ||
170 | { encode = Url.encode | ||
171 | , decode = Url.decode | ||
172 | , chop = Url.chop | ||
173 | , unchop = Url.unchop | ||
174 | } | ||