Slim numerical data compression 1.0
slimlib.cpp File Reference

The C-linkable sliblib library that wraps the underlying C++ classes. More...

#include <string.h>
#include <unistd.h>
#include "slimlib.h"
#include "slim.h"

Classes

struct  slimlib_file_t
 All important elements of the SLIMFILE. More...
 

Typedefs

typedef struct slimlib_file_t SLIMFILE
 The external name is SLIMFILE.
 

Enumerations

enum  slimlib_mode_t { SLIMLIB_READ , SLIMLIB_WRITE }
 Select the read/write mode. More...
 

Functions

SLIMFILEslimopen (const char *filename, const char *modes)
 The following symbols need to be linkable from C.
 
SLIMFILEslimdopen (int fd, const char *modes)
 Associate SLIMFILE for reading or writing with an existing file descriptor But as of October 2009, writing is NOT YET IMPLEMENTED!
 
int slimclose (SLIMFILE *sf)
 Close an open SLIMFILE.
 
long slimtell (SLIMFILE *sf)
 Return the current position in the file (bytes from the start).
 
size_t slimread (void *ptr, size_t size, size_t nmemb, SLIMFILE *sf)
 Read bytes from open SLIMFILE into a buffer.
 
void slimrewind (SLIMFILE *sf)
 Rewind the current position pointer in the file to the beginning.
 
int slimseek (SLIMFILE *sf, long offset, int whence)
 Seek to a point in the file (analogue of fseek, which see for meaning of offset and whence).
 
long slimrawsize (const char *filename)
 Return the raw size of a compressed slim file.
 
long slimdrawsize (int fd)
 

Detailed Description

The C-linkable sliblib library that wraps the underlying C++ classes.

Enumeration Type Documentation

◆ slimlib_mode_t

Select the read/write mode.

Enumerator
SLIMLIB_READ 

This SLIMFILE object is for reading slim data.

SLIMLIB_WRITE 

This SLIMFILE object is for writing slim data.

Function Documentation

◆ slimclose()

int slimclose ( SLIMFILE * sf)

Close an open SLIMFILE.

Parameters
sfThe open SLIMFILE.

References slimlib_file_t::compressor, slimlib_file_t::expander, and slimlib_file_t::fd.

Referenced by slimdopen(), and slimopen().

◆ slimdopen()

SLIMFILE * slimdopen ( int fd,
const char * modes )

Associate SLIMFILE for reading or writing with an existing file descriptor But as of October 2009, writing is NOT YET IMPLEMENTED!

Parameters
fdThe descriptor of the open file.
modesModes codes as in fopen. Only "r" or "w" are used. At present, only "r" is allowed. Must be compatible with the mode of the file descriptor.
Returns
The open SLIMFILE, or NULL if opening fails.

This must be a duplicate because slim_expander_t will steal the fd.

References slimlib_file_t::bytes_used, slimlib_file_t::compressor, slimlib_file_t::expander, slimlib_file_t::fd, slimlib_file_t::mode, slimlib_file_t::nchan, slimlib_file_t::nframes, slimclose(), SLIMLIB_READ, SLIMLIB_WRITE, and slimlib_file_t::writing_is_underway.

◆ slimopen()

SLIMFILE * slimopen ( const char * filename,
const char * modes )

The following symbols need to be linkable from C.

Open a SLIMFILE for reading or writing. But as of October 2009, writing is NOT YET IMPLEMENTED!

Parameters
filenameThe file to open.
modesModes codes as in fopen. Only "r" or "w" are used. At present, only "r" is allowed.
Returns
The open SLIMFILE, or NULL if opening fails.

References slimlib_file_t::bytes_used, slimlib_file_t::compressor, slimlib_file_t::expander, slimlib_file_t::fd, slimlib_file_t::mode, slimlib_file_t::nchan, slimlib_file_t::nframes, slimclose(), SLIMLIB_READ, SLIMLIB_WRITE, and slimlib_file_t::writing_is_underway.

◆ slimrawsize()

long slimrawsize ( const char * filename)

Return the raw size of a compressed slim file.

Must open the file and read its header.

Parameters
filenameThe file to test by reading its header.

Referenced by slimseek().

◆ slimread()

size_t slimread ( void * ptr,
size_t size,
size_t nmemb,
SLIMFILE * sf )

Read bytes from open SLIMFILE into a buffer.

Parameters
ptrBuffer to be filled by data from file.
sizeSize of each data word (in bytes).
nmembNumber of data words to read.
sfOpen SLIMFILE to read from.
Returns
Number of words actually read. This will be 0 if slim raises an error.

References slimlib_file_t::bytes_used, and slimlib_file_t::expander.

◆ slimrewind()

void slimrewind ( SLIMFILE * sf)

Rewind the current position pointer in the file to the beginning.

Implemented by closing the file and starting again.

Parameters
sfThe open SLIMFILE.

References slimlib_file_t::bytes_used, slimlib_file_t::expander, slimlib_file_t::fd, slimlib_file_t::mode, and SLIMLIB_READ.

Referenced by slimseek().

◆ slimseek()

int slimseek ( SLIMFILE * sf,
long offset,
int whence )

Seek to a point in the file (analogue of fseek, which see for meaning of offset and whence).

Parameters
sfThe open SLIMFILE.
offsetByte requested, relative to beginning, current point, or end.
whenceMay be SEEK_SET, SEEK_CUR, or SEEK_END.
Returns
0 on success, -1 on error.

References slimlib_file_t::bytes_used, slimlib_file_t::expander, slimlib_file_t::fd, slimrawsize(), slimrewind(), and slimseek().

Referenced by slimseek().

◆ slimtell()

long slimtell ( SLIMFILE * sf)

Return the current position in the file (bytes from the start).

Parameters
sfThe open SLIMFILE.

References slimlib_file_t::bytes_used.