Esempio n. 1
0
int
hydra_post_save (hydra_post_t *self, const char *filename)
{
    assert (self);
    assert (filename);

    //  Creeate subdirectories if necessary
    zsys_dir_create ("posts");
    zsys_dir_create ("posts/blobs");

    //  If post content hasn't yet been serialised, write it to disk in the
    //  blobs directory and set the location property to point to it.
    if (self->content) {
        assert (!self->location);
        self->location = zsys_sprintf ("posts/blobs/%s", self->digest);
        FILE *output = fopen (self->location, "wb");
        zchunk_write (self->content, output);
        zchunk_destroy (&self->content);
        fclose (output);
    }
    zconfig_t *root = zconfig_new ("root", NULL);
    zconfig_put (root, "/post/ident", hydra_post_ident (self));
    zconfig_put (root, "/post/subject", self->subject);
    zconfig_put (root, "/post/timestamp", self->timestamp);
    zconfig_put (root, "/post/parent-id", self->parent_id);
    zconfig_put (root, "/post/mime-type", self->mime_type);
    zconfig_put (root, "/post/digest", self->digest);
    zconfig_put (root, "/post/location", self->location);
    zconfig_putf (root, "/post/content-size", "%ld", self->content_size);
    zconfig_savef (root, "posts/%s", filename);
    zconfig_destroy (&root);
    return 0;
}
Esempio n. 2
0
File: zfile.c Progetto: DeanHH/czmq
int
zfile_write (zfile_t *self, zchunk_t *chunk, off_t offset)
{
    assert (self);
    assert (self->handle);
    int rc = fseek (self->handle, (long) offset, SEEK_SET);
    if (rc >= 0)
        rc = zchunk_write (chunk, self->handle);
    return rc;
}
Esempio n. 3
0
///
//  Write chunk to an open file descriptor
int QZchunk::write (FILE *handle)
{
    int rv = zchunk_write (self, handle);
    return rv;
}