2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
// PDF stream functions for pdfio.
|
|
|
|
|
//
|
|
|
|
|
// Copyright © 2021 by Michael R Sweet.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
// information.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Include necessary headers...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "pdfio-private.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// 'pdfioStreamClose()' - Close a (data) stream in a PDF file.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioStreamClose(pdfio_stream_t *st) // I - Stream
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// TODO: Implement me
|
|
|
|
|
(void)st;
|
|
|
|
|
return (false);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-02 04:38:11 +02:00
|
|
|
|
//
|
|
|
|
|
// 'pdfioStreamConsume()' - Consume bytes from the stream.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on EOF
|
|
|
|
|
pdfioStreamConsume(pdfio_stream_t *st, // I - Stream
|
|
|
|
|
size_t bytes)// I - Number of bytes to consume
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement me
|
|
|
|
|
(void)st;
|
|
|
|
|
(void)bytes;
|
|
|
|
|
return (false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 03:09:43 +02:00
|
|
|
|
//
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// '_pdfioStreamDelete()' - Free all memory used by a stream.
|
2021-04-17 03:09:43 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
void
|
|
|
|
|
_pdfioStreamDelete(pdfio_stream_t *st) // I - Stream
|
2021-04-17 03:09:43 +02:00
|
|
|
|
{
|
2021-04-30 13:06:56 +02:00
|
|
|
|
if (st->filter == PDFIO_FILTER_FLATE)
|
|
|
|
|
{
|
|
|
|
|
// Free memory used for flate compression/decompression...
|
|
|
|
|
if (st->pdf->mode == _PDFIO_MODE_READ)
|
|
|
|
|
inflateEnd(&st->flate);
|
|
|
|
|
else // mode == _PDFIO_MODE_WRITE
|
|
|
|
|
deflateEnd(&st->flate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(st);
|
2021-04-17 03:09:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-26 16:42:01 +02:00
|
|
|
|
//
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// 'pdfioStreamGetToken()' - Read a single PDF token from a stream.
|
2021-04-26 16:42:01 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
bool // O - `true` on success, `false` on EOF
|
|
|
|
|
pdfioStreamGetToken(
|
|
|
|
|
pdfio_stream_t *st, // I - Stream
|
|
|
|
|
char *buffer, // I - String buffer
|
|
|
|
|
size_t bufsize) // I - Size of string buffer
|
2021-05-01 23:50:52 +02:00
|
|
|
|
{
|
2021-05-02 04:38:11 +02:00
|
|
|
|
return (_pdfioTokenRead(st->pdf, buffer, bufsize, (_pdfio_tpeek_cb_t)pdfioStreamPeek, (_pdfio_tconsume_cb_t)pdfioStreamConsume, st));
|
2021-05-01 23:50:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'pdfioStreamPeek()' - Peek at data in a stream.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
ssize_t // O - Bytes returned or `-1` on error
|
|
|
|
|
pdfioStreamPeek(pdfio_stream_t *st, // I - Stream
|
|
|
|
|
void *buffer, // I - Buffer
|
|
|
|
|
size_t bytes) // I - Size of buffer
|
2021-04-26 16:42:01 +02:00
|
|
|
|
{
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// TODO: Implement me
|
|
|
|
|
(void)st;
|
|
|
|
|
(void)buffer;
|
2021-05-01 23:50:52 +02:00
|
|
|
|
(void)bytes;
|
2021-04-30 13:06:56 +02:00
|
|
|
|
|
2021-05-01 23:50:52 +02:00
|
|
|
|
return (-1);
|
2021-04-26 16:42:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// 'pdfioStreamPrintf()' - Write a formatted string to a stream.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioStreamPrintf(
|
|
|
|
|
pdfio_stream_t *st, // I - Stream
|
|
|
|
|
const char *format, // I - `printf`-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-30 13:06:56 +02:00
|
|
|
|
char buffer[8192]; // String buffer
|
|
|
|
|
va_list ap; // Argument pointer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Format the string...
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
// Write the string...
|
|
|
|
|
return (pdfioStreamWrite(st, buffer, strlen(buffer)));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// 'pdfioStreamPuts()' - Write a literal string to a stream.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioStreamPuts(pdfio_stream_t *st, // I - Stream
|
|
|
|
|
const char *s) // I - Literal string
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-30 13:06:56 +02:00
|
|
|
|
if (!st || !s)
|
|
|
|
|
return (false);
|
|
|
|
|
else
|
|
|
|
|
return (pdfioStreamWrite(st, s, strlen(s)));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// 'pdfioStreamRead()' - Read data from a stream.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
ssize_t // O - Number of bytes read or `-1` on error
|
|
|
|
|
pdfioStreamRead(
|
|
|
|
|
pdfio_stream_t *st, // I - Stream
|
|
|
|
|
void *buffer, // I - Buffer
|
|
|
|
|
size_t bytes) // I - Bytes to read
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// TODO: Implement me
|
|
|
|
|
(void)st;
|
|
|
|
|
(void)buffer;
|
|
|
|
|
(void)bytes;
|
|
|
|
|
|
|
|
|
|
return (-1);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// 'pdfioStreamWrite()' - Write data to a stream.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
bool // O - `true` on success or `false` on failure
|
|
|
|
|
pdfioStreamWrite(
|
|
|
|
|
pdfio_stream_t *st, // I - Stream
|
|
|
|
|
const void *buffer, // I - Data to write
|
|
|
|
|
size_t bytes) // I - Number of bytes to write
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-30 13:06:56 +02:00
|
|
|
|
// TODO: Implement me
|
|
|
|
|
(void)st;
|
|
|
|
|
(void)buffer;
|
|
|
|
|
(void)bytes;
|
2021-04-17 02:41:46 +02:00
|
|
|
|
|
2021-04-30 13:06:56 +02:00
|
|
|
|
return (false);
|
|
|
|
|
}
|