]>
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. Derived from the fd convenience
17 functions in the libbz2 package. */
19 #include "compress_bz.h"
25 compress_bz::compress_bz (io_stream
* parent
) : peeklen (0), position (0)
27 /* read only via this constructor */
30 if (!parent
|| parent
->error ())
43 int ret
= BZ2_bzDecompressInit (&(strm
), 0, 0);
55 compress_bz::read (void *buffer
, size_t len
)
57 if (!initialisedOk
|| writing
)
64 ssize_t tmplen
= std::min (peeklen
, len
);
66 memcpy (buffer
, peekbuf
, tmplen
);
67 memmove (peekbuf
, peekbuf
+ tmplen
, tmplen
);
68 ssize_t tmpread
= read (&((char *) buffer
)[tmplen
], len
- tmplen
);
70 return tmpread
+ tmplen
;
76 strm
.next_out
= (char *) buffer
;
80 if (original
->error ())
82 lasterr
= original
->error ();
85 if (strm
.avail_in
== 0 && rlen
> 0)
87 rlen
= original
->read (buf
, 4096);
90 if (original
->error ())
91 lasterr
= original
->error ();
101 ret
= BZ2_bzDecompress (&strm
);
102 if (ret
!= BZ_OK
&& ret
!= BZ_STREAM_END
)
107 if (ret
== BZ_OK
&& rlen
== 0 && strm
.avail_out
)
109 /* unexpected end of file */
113 if (ret
== BZ_STREAM_END
)
115 position
+= len
- strm
.avail_out
;
116 return len
- strm
.avail_out
;
118 if (strm
.avail_out
== 0)
129 ssize_t
compress_bz::write (const void *buffer
, size_t len
)
131 throw new logic_error ("compress_bz::write is not implemented");
134 ssize_t
compress_bz::peek (void *buffer
, size_t len
)
142 /* can only peek 512 bytes */
148 size_t want
= len
- peeklen
;
149 ssize_t got
= read (&peekbuf
[peeklen
], want
);
156 /* we may have read less than requested. */
157 memcpy (buffer
, peekbuf
, peeklen
);
162 memcpy (buffer
, peekbuf
, len
);
172 throw new logic_error ("compress_bz::tell is not implemented "
178 compress_bz::seek (long where
, io_stream_seek_t whence
)
180 throw new logic_error ("compress_bz::seek is not implemented");
184 compress_bz::error ()
190 compress_bz::set_mtime (int time
)
193 return original
->set_mtime (time
);
198 compress_bz::get_mtime ()
201 return original
->get_mtime ();
205 compress_bz::~compress_bz ()
208 BZ2_bzDecompressEnd (&strm
);
This page took 0.047239 seconds and 5 git commands to generate.