OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 // | |
5 // BZip2Filter applies bzip2 content encoding/decoding to a datastream. | |
6 // Since it is a new feature, and no specification said what 's bzip2 content | |
7 // composed of in http protocol. So I assume with bzip2 encoding the content | |
8 // is full format, which means the content should carry complete bzip2 head, | |
9 // such as inlcude magic number 1(BZh), block size bit, magic number 2(0x31, | |
10 // 0x41, 0x59, 0x26, 0xx53, 0x59) | |
11 // Maybe need to inserts a bzlib2 header to the data stream before calling | |
12 // decompression functionality, but at now I do not meet this sort of real | |
13 // scenarios. So let's see the further requests. | |
14 // | |
15 // This BZip2Filter internally uses third_party/bzip2 library to do decoding. | |
16 // | |
17 // BZip2Filter is also a subclass of Filter. See the latter's header file | |
18 // filter.h for sample usage. | |
19 | |
20 #ifndef NET_BASE_BZIP2_FILTER_H_ | |
21 #define NET_BASE_BZIP2_FILTER_H_ | |
22 | |
23 #if defined(USE_SYSTEM_LIBBZ2) | |
24 #include <bzlib.h> | |
25 #else | |
26 #include "third_party/bzip2/bzlib.h" | |
27 #endif | |
28 | |
29 #include "base/scoped_ptr.h" | |
30 #include "net/base/filter.h" | |
31 | |
32 class BZip2Filter : public Filter { | |
33 public: | |
34 explicit BZip2Filter(const FilterContext& filter_context); | |
35 | |
36 virtual ~BZip2Filter(); | |
37 | |
38 // Initializes filter decoding mode and internal control blocks. | |
39 // Parameter use_small_memory specifies whether use small memory | |
40 // to decompresss data. If small is nonzero, the bzip2 library will | |
41 // use an alternative decompression algorithm which uses less memory | |
42 // but at the cost of decompressing more slowly (roughly speaking, | |
43 // half the speed, but the maximum memory requirement drops to | |
44 // around 2300k). For more information, see doc in http://www.bzip.org. | |
45 // The function returns true if success and false otherwise. | |
46 // The filter can only be initialized once. | |
47 bool InitDecoding(bool use_small_memory); | |
48 | |
49 // Decodes the pre-filter data and writes the output into the dest_buffer | |
50 // passed in. | |
51 // The function returns FilterStatus. See filter.h for its description. | |
52 // | |
53 // Since BZ2_bzDecompress need a full BZip header for decompression, so | |
54 // the incoming data should have the full BZip header, otherwise this | |
55 // function will give you nothing with FILTER_ERROR. | |
56 // | |
57 // Upon entry, *dest_len is the total size (in number of chars) of the | |
58 // destination buffer. Upon exit, *dest_len is the actual number of chars | |
59 // written into the destination buffer. | |
60 // | |
61 // This function will fail if there is no pre-filter data in the | |
62 // stream_buffer_. On the other hand, *dest_len can be 0 upon successful | |
63 // return. For example, the internal zlib may process some pre-filter data | |
64 // but not produce output yet. | |
65 virtual FilterStatus ReadFilteredData(char* dest_buffer, int* dest_len); | |
66 | |
67 private: | |
68 enum DecodingStatus { | |
69 DECODING_UNINITIALIZED, | |
70 DECODING_IN_PROGRESS, | |
71 DECODING_DONE, | |
72 DECODING_ERROR | |
73 }; | |
74 | |
75 // Tracks the status of decoding. | |
76 // This variable is initialized by InitDecoding and updated only by | |
77 // ReadFilteredData. | |
78 DecodingStatus decoding_status_; | |
79 | |
80 // The control block of bzip which actually does the decoding. | |
81 // This data structure is initialized by InitDecoding and updated in | |
82 // ReadFilteredData. | |
83 scoped_ptr<bz_stream> bzip2_data_stream_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(BZip2Filter); | |
86 }; | |
87 | |
88 #endif // NET_BASE_BZIP2_FILTER_H_ | |
OLD | NEW |