]>
cygwin.com Git - cygwin-apps/setup.git/blob - compress_bz.cc
2 * Copyright (c) 2001, Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 /* Archive IO operations for bz2 files.
17 derived from the fd convenience functions in the libbz2 package.
21 static const char *cvsid
=
31 #include "io_stream.h"
33 #include "compress_bz.h"
37 compress_bz::compress_bz (io_stream
* parent
) : peeklen (0), position (0)
39 /* read only via this constructor */
42 if (!parent
|| parent
->error ())
55 int ret
= BZ2_bzDecompressInit (&(strm
), 0, 0);
67 compress_bz::read (void *buffer
, size_t len
)
69 if (!initialisedOk
|| writing
)
76 ssize_t tmplen
= min (peeklen
, len
);
78 memcpy (buffer
, peekbuf
, tmplen
);
79 memmove (peekbuf
, peekbuf
+ tmplen
, tmplen
);
80 ssize_t tmpread
= read (&((char *) buffer
)[tmplen
], len
- tmplen
);
82 return tmpread
+ tmplen
;
88 strm
.next_out
= (char *) buffer
;
93 if (original
->error ())
95 lasterr
= original
->error ();
98 if (strm
.avail_in
== 0 && rlen
> 0)
100 rlen
= original
->read (buf
, 4096);
107 strm
.avail_in
= rlen
;
111 ret
= BZ2_bzDecompress (&strm
);
112 if (ret
!= BZ_OK
&& ret
!= BZ_STREAM_END
)
117 if (ret
== BZ_OK
&& rlen
== 0 && strm
.avail_out
)
119 /* unexpected end of file */
123 if (ret
== BZ_STREAM_END
)
125 position
+= len
- strm
.avail_out
;
126 return len
- strm
.avail_out
;
128 if (strm
.avail_out
== 0)
139 ssize_t
compress_bz::write (const void *buffer
, size_t len
)
141 log (LOG_TIMESTAMP
, "compress_bz::write called");
145 ssize_t
compress_bz::peek (void *buffer
, size_t len
)
152 /* can only peek 512 bytes */
158 size_t want
= len
- peeklen
;
159 ssize_t got
= read (&peekbuf
[peeklen
], want
);
165 /* we may have read less than requested. */
166 memcpy (buffer
, peekbuf
, peeklen
);
171 memcpy (buffer
, peekbuf
, len
);
182 log (LOG_TIMESTAMP
, "compress_bz::tell called for writing mode");
189 compress_bz::seek (long where
, io_stream_seek_t whence
)
191 log (LOG_TIMESTAMP
, "compress_bz::seek called");
196 compress_bz::error ()
198 log (LOG_TIMESTAMP
, "compress_bz::error called");
203 compress_bz::set_mtime (int time
)
206 return original
->set_mtime (time
);
211 compress_bz::get_mtime ()
214 return original
->get_mtime ();
218 compress_bz::~compress_bz ()
221 BZ2_bzDecompressEnd (&strm
);
This page took 0.05114 seconds and 6 git commands to generate.