]>
git.saurik.com Git - wxWidgets.git/blob - src/common/zipstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: input stream for ZIP archive access
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation
13 #include <wx/wxprec.h>
23 #include <wx/stream.h>
24 #include <wx/wfstream.h>
25 #include <wx/zipstream.h>
31 wxZipInputStream::wxZipInputStream(const wxString
& archive
, const wxString
& file
) : wxInputStream()
37 m_Archive
= (void*) unzOpen(archive
);
38 if (m_Archive
== NULL
) {
39 m_lasterror
= wxStream_READ_ERR
;
42 if (unzLocateFile((unzFile
)m_Archive
, file
, 0) != UNZ_OK
) {
43 m_lasterror
= wxStream_READ_ERR
;
46 unzGetCurrentFileInfo((unzFile
)m_Archive
, &zinfo
, NULL
, 0, NULL
, 0, NULL
, 0);
48 if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
) {
49 m_lasterror
= wxStream_READ_ERR
;
52 m_Size
= zinfo
.uncompressed_size
;
57 wxZipInputStream::~wxZipInputStream()
61 unzCloseCurrentFile((unzFile
)m_Archive
);
62 unzClose((unzFile
)m_Archive
);
68 size_t wxZipInputStream::OnSysRead(void *buffer
, size_t bufsize
)
70 if (m_Pos
+ bufsize
> m_Size
) bufsize
= m_Size
- m_Pos
;
71 unzReadCurrentFile((unzFile
)m_Archive
, buffer
, bufsize
);
78 off_t
wxZipInputStream::OnSysSeek(off_t seek
, wxSeekMode mode
)
84 case wxFromCurrent
: nextpos
= seek
+ m_Pos
; break;
85 case wxFromStart
: nextpos
= seek
; break;
86 case wxFromEnd
: nextpos
= m_Size
- 1 + seek
; break;
87 default : nextpos
= m_Pos
; break; /* just to fool compiler, never happens */
91 if (nextpos
> m_Pos
) {
92 buf
= malloc(nextpos
- m_Pos
);
93 unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos
- m_Pos
);
96 else if (nextpos
< m_Pos
) {
97 unzCloseCurrentFile((unzFile
)m_Archive
);
98 if (unzOpenCurrentFile((unzFile
)m_Archive
) != UNZ_OK
) {
99 m_lasterror
= wxStream_READ_ERR
;
102 buf
= malloc(nextpos
);
103 unzReadCurrentFile((unzFile
)m_Archive
, buf
, nextpos
);