Skip to content

Commit

Permalink
Add passim_item_set_stream() for future use
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsie committed Dec 31, 2023
1 parent bfc3a52 commit 4f626c9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libpassim/passim-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ passim_client_publish(PassimClient *self, PassimItem *item, GError **error)
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

/* set out of band file descriptor */
if (passim_item_get_file(item) != NULL) {
if (passim_item_get_stream(item) != NULL) {
istream = g_object_ref(G_UNIX_INPUT_STREAM(passim_item_get_stream(item)));
} else if (passim_item_get_file(item) != NULL) {
g_autofree gchar *filename = g_file_get_path(passim_item_get_file(item));
istream = passim_client_input_stream_from_filename(filename, error);
if (istream == NULL)
Expand Down
43 changes: 43 additions & 0 deletions libpassim/passim-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "config.h"

#include <gio/gunixinputstream.h>

#include "passim-item.h"

/**
Expand All @@ -25,6 +27,7 @@ typedef struct {
guint64 size;
GFile *file;
GBytes *bytes;
GInputStream *stream;
GDateTime *ctime;
} PassimItemPrivate;

Expand Down Expand Up @@ -409,6 +412,44 @@ passim_item_set_bytes(PassimItem *self, GBytes *bytes)
priv->hash = g_compute_checksum_for_bytes(G_CHECKSUM_SHA256, bytes);
}

/**
* passim_item_get_stream:
* @self: a #PassimItem
*
* Gets the input stream for the item.
*
* Returns: (transfer none): a #GInputStream, or %NULL if unset
*
* Since: 0.1.5
**/
GInputStream *
passim_item_get_stream(PassimItem *self)
{
PassimItemPrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(PASSIM_IS_ITEM(self), NULL);
return priv->stream;
}

/**
* passim_item_set_stream:
* @self: a #PassimItem
* @stream: (nullable): a #GInputStream
*
* Sets the input stream stream for the item.
*
* NOTE: This *MUST* be a #GUnixInputStream, or subclass thereof.
*
* Since: 0.1.5
**/
void
passim_item_set_stream(PassimItem *self, GInputStream *stream)
{
PassimItemPrivate *priv = GET_PRIVATE(self);
g_return_if_fail(PASSIM_IS_ITEM(self));
g_return_if_fail(G_IS_UNIX_INPUT_STREAM(stream));
g_set_object(&priv->stream, stream);
}

/**
* passim_item_get_ctime:
* @self: a #PassimItem
Expand Down Expand Up @@ -850,6 +891,8 @@ passim_item_finalize(GObject *object)
g_object_unref(priv->file);
if (priv->bytes != NULL)
g_bytes_unref(priv->bytes);
if (priv->stream != NULL)
g_object_unref(priv->stream);
if (priv->ctime != NULL)
g_date_time_unref(priv->ctime);
g_free(priv->hash);
Expand Down
4 changes: 4 additions & 0 deletions libpassim/passim-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ GBytes *
passim_item_get_bytes(PassimItem *self);
void
passim_item_set_bytes(PassimItem *self, GBytes *bytes);
GInputStream *
passim_item_get_stream(PassimItem *self);
void
passim_item_set_stream(PassimItem *self, GInputStream *stream);
GDateTime *
passim_item_get_ctime(PassimItem *self);
void
Expand Down
7 changes: 7 additions & 0 deletions libpassim/passim.map
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ LIBPASSIM_0.1.2 {
passim_item_set_size;
local: *;
} LIBPASSIM_0.1.0;

LIBPASSIM_0.1.5 {
global:
passim_item_get_stream;
passim_item_set_stream;
local: *;
} LIBPASSIM_0.1.2;

0 comments on commit 4f626c9

Please sign in to comment.