]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/src/gzip.cpp
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 // To configure Boost to work with libbz2, see the
9 // installation instructions here:
10 // http://boost.org/libs/iostreams/doc/index.html?path=7
12 // Define BOOST_IOSTREAMS_SOURCE so that <boost/iostreams/detail/config.hpp>
13 // knows that we are building the library (possibly exporting code), rather
14 // than using it (possibly importing code).
15 #define BOOST_IOSTREAMS_SOURCE
17 #include <boost/iostreams/detail/config/dyn_link.hpp>
18 #include <boost/iostreams/filter/gzip.hpp>
19 #include <boost/throw_exception.hpp>
21 namespace boost
{ namespace iostreams
{
23 //------------------Implementation of gzip_header-----------------------------//
27 void gzip_header::process(char c
)
29 uint8_t value
= static_cast<uint8_t>(c
);
32 if (value
!= gzip::magic::id1
)
33 boost::throw_exception(gzip_error(gzip::bad_header
));
37 if (value
!= gzip::magic::id2
)
38 boost::throw_exception(gzip_error(gzip::bad_header
));
42 if (value
!= gzip::method::deflate
)
43 boost::throw_exception(gzip_error(gzip::bad_method
));
51 mtime_
+= value
<< (offset_
* 8);
64 if (flags_
& gzip::flags::extra
) {
66 } else if (flags_
& gzip::flags::name
) {
68 } else if (flags_
& gzip::flags::comment
) {
70 } else if (flags_
& gzip::flags::header_crc
) {
77 xlen_
+= value
<< (offset_
* 8);
87 if (flags_
& gzip::flags::name
) {
89 } else if (flags_
& gzip::flags::comment
) {
91 } else if (flags_
& gzip::flags::header_crc
) {
101 } else if (flags_
& gzip::flags::comment
) {
103 } else if (flags_
& gzip::flags::header_crc
) {
112 } else if (flags_
& gzip::flags::header_crc
) {
131 void gzip_header::reset()
135 os_
= flags_
= offset_
= xlen_
= 0;
140 //------------------Implementation of gzip_footer-----------------------------//
142 void gzip_footer::process(char c
)
144 uint8_t value
= static_cast<uint8_t>(c
);
145 if (state_
== s_crc
) {
146 crc_
+= value
<< (offset_
* 8);
153 } else if (state_
== s_isize
) {
154 isize_
+= value
<< (offset_
* 8);
166 void gzip_footer::reset()
168 crc_
= isize_
= offset_
= 0;
172 } // End namespace boost::iostreams::detail.
174 } } // End namespaces iostreams, boost.