libopc
Data Structures | Macros | Typedefs | Functions
zip.h File Reference
#include <opc/config.h>
#include <opc/file.h>
#include <opc/container.h>

Go to the source code of this file.

Data Structures

struct  OPC_ZIP_SEGMENT_INFO_STRUCT
 

Macros

#define OPC_DEFAULT_GROWTH_HINT   512
 

Typedefs

typedef struct OPC_ZIP_STRUCT opcZip
 
typedef struct OPC_ZIPINPUTSTREAM_STRUCT opcZipInputStream
 
typedef struct OPC_ZIPOUTPUTSTREAM_STRUCT opcZipOutputStream
 
typedef struct OPC_ZIP_SEGMENT_INFO_STRUCT opcZipSegmentInfo_t
 
typedef int opcZipLoaderOpenCallback(void *iocontext)
 
typedef int opcZipLoaderSkipCallback(void *iocontext)
 
typedef int opcZipLoaderReadCallback(void *iocontext, char *buffer, int len)
 
typedef int opcZipLoaderCloseCallback(void *iocontext)
 
typedef opc_error_topcZipLoaderSegmentCallback_t) (void *iocontext, void *userctx, opcZipSegmentInfo_t *info, opcZipLoaderOpenCallback *open, opcZipLoaderReadCallback *read, opcZipLoaderCloseCallback *close, opcZipLoaderSkipCallback *skip)
 
typedef opc_error_topcZipSegmentReleaseCallback) (opcZip *zip, opc_uint32_t segment_id)
 

Functions

opc_error_t opcZipLoader (opcIO_t *io, void *userctx, opcZipLoaderSegmentCallback_t *segmentCallback)
 
void opcZipClose (opcZip *zip, opcZipSegmentReleaseCallback *releaseCallback)
 
opcZipopcZipCreate (opcIO_t *io)
 
opc_error_t opcZipCommit (opcZip *zip, opc_bool_t trim)
 
opc_error_t opcZipGC (opcZip *zip)
 
opc_uint32_t opcZipLoadSegment (opcZip *zip, const xmlChar *partName, opc_bool_t rels_segment, opcZipSegmentInfo_t *info)
 
opc_uint32_t opcZipCreateSegment (opcZip *zip, const xmlChar *partName, opc_bool_t relsSegment, opc_uint32_t segment_size, opc_uint32_t growth_hint, opc_uint16_t compression_method, opc_uint16_t bit_flag)
 
opcZipInputStreamopcZipOpenInputStream (opcZip *zip, opc_uint32_t segment_id)
 
opc_error_t opcZipCloseInputStream (opcZip *zip, opcZipInputStream *stream)
 
opc_uint32_t opcZipReadInputStream (opcZip *zip, opcZipInputStream *stream, opc_uint8_t *buf, opc_uint32_t buf_len)
 
opcZipOutputStreamopcZipCreateOutputStream (opcZip *zip, opc_uint32_t *segment_id, const xmlChar *partName, opc_bool_t relsSegment, opc_uint32_t segment_size, opc_uint32_t growth_hint, opc_uint16_t compression_method, opc_uint16_t bit_flag)
 
opcZipOutputStreamopcZipOpenOutputStream (opcZip *zip, opc_uint32_t *segment_id)
 
opc_error_t opcZipCloseOutputStream (opcZip *zip, opcZipOutputStream *stream, opc_uint32_t *segment_id)
 
opc_uint32_t opcZipWriteOutputStream (opcZip *zip, opcZipOutputStream *stream, const opc_uint8_t *buf, opc_uint32_t buf_len)
 
opc_uint32_t opcZipGetFirstSegmentId (opcZip *zip)
 
opc_uint32_t opcZipGetNextSegmentId (opcZip *zip, opc_uint32_t segment_id)
 
opc_error_t opcZipGetSegmentInfo (opcZip *zip, opc_uint32_t segment_id, const xmlChar **name, opc_bool_t *rels_segment, opc_uint32_t *crc)
 
opc_bool_t opcZipSegmentDelete (opcZip *zip, opc_uint32_t *first_segment, opc_uint32_t *last_segment, opcZipSegmentReleaseCallback *releaseCallback)
 

Detailed Description

The ZIP file backend of an OPC container.

Macro Definition Documentation

#define OPC_DEFAULT_GROWTH_HINT   512

Default growth hint of an OPC stream.

Typedef Documentation

typedef struct OPC_ZIP_STRUCT opcZip

Handle to a ZIP archive.

See also
internal.h

Handle to a raw ZIP input stream.

See also
internal.h
typedef int opcZipLoaderCloseCallback(void *iocontext)
typedef int opcZipLoaderOpenCallback(void *iocontext)
typedef int opcZipLoaderReadCallback(void *iocontext, char *buffer, int len)
typedef opc_error_t( opcZipLoaderSegmentCallback_t) (void *iocontext, void *userctx, opcZipSegmentInfo_t *info, opcZipLoaderOpenCallback *open, opcZipLoaderReadCallback *read, opcZipLoaderCloseCallback *close, opcZipLoaderSkipCallback *skip)
See also
opcZipLoader
typedef int opcZipLoaderSkipCallback(void *iocontext)

Handle to a raw ZIP output stream.

See also
internal.h

Holds all information of a ZIP segment.

typedef opc_error_t( opcZipSegmentReleaseCallback) (opcZip *zip, opc_uint32_t segment_id)
See also
opcZipClose

Function Documentation

void opcZipClose ( opcZip zip,
opcZipSegmentReleaseCallback releaseCallback 
)

Closes the ZIP archive zip and will call releaseCallback for every segment to give the implementer a chance to free user resources.

Examples:
opc_zipextract.c, and opc_zipwrite.c.
opc_error_t opcZipCloseInputStream ( opcZip zip,
opcZipInputStream stream 
)

Free all resources of the input stream.

Examples:
opc_zipextract.c.
opc_error_t opcZipCloseOutputStream ( opcZip zip,
opcZipOutputStream stream,
opc_uint32_t segment_id 
)

Will close the stream and free all resources. Additionally the new segment id will be stored in *segment_id.

See also
opcZipOpenOutputStream
Examples:
opc_zipwrite.c.
opc_error_t opcZipCommit ( opcZip zip,
opc_bool_t  trim 
)

Commits all buffers and writes the ZIP archives local header directories. if trim is true then padding bytes will be removed, i.e. the ZIP file size fill be minimalized.

Examples:
opc_zipwrite.c.
opcZip* opcZipCreate ( opcIO_t io)

Creates an empty ZIP archive with the given io.

Examples:
opc_zipextract.c, and opc_zipwrite.c.
opcZipOutputStream* opcZipCreateOutputStream ( opcZip zip,
opc_uint32_t segment_id,
const xmlChar *  partName,
opc_bool_t  relsSegment,
opc_uint32_t  segment_size,
opc_uint32_t  growth_hint,
opc_uint16_t  compression_method,
opc_uint16_t  bit_flag 
)

Creates an output stream for the segment with segment_id. If *segment_id is -1 then a new segment will be created. Otherwise the segment with *segment_id will be overwritten.

opc_uint32_t opcZipCreateSegment ( opcZip zip,
const xmlChar *  partName,
opc_bool_t  relsSegment,
opc_uint32_t  segment_size,
opc_uint32_t  growth_hint,
opc_uint16_t  compression_method,
opc_uint16_t  bit_flag 
)

Create a segment with the given parameters.

Returns
Returns the segment_id.
Examples:
opc_zipwrite.c.
opc_error_t opcZipGC ( opcZip zip)

Garbage collection on the passed zip archive. This will e.g. make deleted files available as free space.

opc_uint32_t opcZipGetFirstSegmentId ( opcZip zip)

Returns the first segment id or -1. Use the following code to iterarte through all segments.

1 for(opc_uint32_t segment_id=opcZipGetFirstSegmentId(zip);
2  -1!=segment_id;
3  segment_id=opcZipGetNextSegmentId(zip, segment_id) {
4  ...
5 }
See also
opcZipGetNextSegmentId
Examples:
opc_zipextract.c, and opc_zipwrite.c.
opc_uint32_t opcZipGetNextSegmentId ( opcZip zip,
opc_uint32_t  segment_id 
)

Returns the next segment id or -1.

See also
opcZipGetFirstSegmentId
Examples:
opc_zipextract.c, and opc_zipwrite.c.
opc_error_t opcZipGetSegmentInfo ( opcZip zip,
opc_uint32_t  segment_id,
const xmlChar **  name,
opc_bool_t rels_segment,
opc_uint32_t crc 
)

Returns info about the given segment id.

Examples:
opc_zipextract.c, and opc_zipwrite.c.
opc_error_t opcZipLoader ( opcIO_t io,
void *  userctx,
opcZipLoaderSegmentCallback_t segmentCallback 
)

Walks every segment in a ZIP archive and calls the segmentCallback callback method. The implementer segmentCallback method must then eiher use the passed open, read and close methods to read the stream or the passed skip methods to skip the stream. This method can be used to e.g. read ZIP file in stream mode.

Examples:
opc_zipextract.c, opc_zipread.c, and opc_zipwrite.c.
opc_uint32_t opcZipLoadSegment ( opcZip zip,
const xmlChar *  partName,
opc_bool_t  rels_segment,
opcZipSegmentInfo_t info 
)

Load segment information into info. If rels_segment is -1 then load the info for part with name partName. Otherwise load the segment information for the ".rels." segment of partName.

Returns
Returns the segment_id.
Examples:
opc_zipextract.c, and opc_zipwrite.c.
opcZipInputStream* opcZipOpenInputStream ( opcZip zip,
opc_uint32_t  segment_id 
)

Creates an input stream for the segment with segment_id.

See also
opcZipLoadSegment
opcZipCreateSegment
Examples:
opc_zipextract.c.
opcZipOutputStream* opcZipOpenOutputStream ( opcZip zip,
opc_uint32_t segment_id 
)

Opens an existing ouput stream for reading. The *segment_id will be set to -1 and reset on opcZipCloseOutputStream.

See also
opcZipCloseOutputStream
Examples:
opc_zipwrite.c.
opc_uint32_t opcZipReadInputStream ( opcZip zip,
opcZipInputStream stream,
opc_uint8_t buf,
opc_uint32_t  buf_len 
)

Read maximal buf_len bytes from the input stream into .

Returns
Returns the number of bytes read.
Examples:
opc_zipextract.c.
opc_bool_t opcZipSegmentDelete ( opcZip zip,
opc_uint32_t first_segment,
opc_uint32_t last_segment,
opcZipSegmentReleaseCallback releaseCallback 
)

Marks a given segments as deleted.

See also
opcZipGC
Examples:
opc_zipwrite.c.
opc_uint32_t opcZipWriteOutputStream ( opcZip zip,
opcZipOutputStream stream,
const opc_uint8_t buf,
opc_uint32_t  buf_len 
)

Write buf_len bytes to buf.

Returns
Returns the number of bytes written.
Examples:
opc_zipwrite.c.