Esempio n. 1
0
static rc_t prepare_compress( const compress_context * ctx,
                              KDirectory *dir, const KFile **src, KFile **dst )
{
    KFile *temp = NULL;

    rc_t rc = KDirectoryOpenFileRead ( dir, src, ctx->src_file );
    DISP_RC( rc, "KDirectoryOpenFileRead() failed" );
    if ( rc != 0 ) return rc;

    rc = KDirectoryCreateFile ( dir, &temp, false, 0664, kcmInit, ctx->dst_file );
    DISP_RC( rc, "KDirectoryCreateFile() failed" );
    if ( rc == 0 )
        switch( ctx->method )
        {
        case KC_GZIP : rc = KFileMakeGzipForWrite ( dst, temp );
                       DISP_RC( rc, "KFileMakeGzipForWrite() failed" );
                       break;
        case KC_BZIP : rc = KFileMakeBzip2ForWrite ( dst, temp );
                       DISP_RC( rc, "KFileMakeBzip2ForWrite() failed" );
                       break;
        case KC_SZIP : /* rc = KFileMakeSzipForWrite ( dst, temp ); */
                       rc = RC( rcExe, rcFile, rcPacking, rcFormat, rcUnknown );
                       DISP_RC( rc, "KFileMakeSzipForWrite() failed" );
                       break;
        }
    KFileRelease ( temp );
    return rc;
}
Esempio n. 2
0
static rc_t make_read_file( cg_dump_opts * opts, struct sg_lookup * lookup, KDirectory * dir, lane * l )
{
    rc_t rc;
    if ( opts->comp == oc_null )
    {
        l->reads = NULL;
        rc = 0;
    }
    else
    {
        const char * ext;
        switch( opts->comp )
        {
            case oc_none : ext = none_ext; break;
            case oc_gzip : ext = gzip_ext; break;
            case oc_bzip : ext = bzip_ext; break;
            case oc_null : ext = none_ext; break;
        }
        rc = KDirectoryCreateFile ( dir, &l->reads, true, 0664, kcmCreate, 
                                    "%s%.*s_%03d.tsv%s", opts->prefix, l->name->len, l->name->addr, l->chunk, ext );
        if ( rc != 0 )
        {
            (void)PLOGERR( klogErr, ( klogErr, rc, "cannot create reads-file for lane '$(lane)' / chunk '$(chunk)'",
                                      "lane=%S,chunk=%d", l->name, l->chunk ) );
        }
        else if ( opts->wbuff_size > 0 )
        {
            KFile * buffered;
            rc = KBufWriteFileMakeWrite ( &buffered, l->reads, opts->wbuff_size );
            if ( rc != 0 )
            {
                (void)PLOGERR( klogErr, ( klogErr, rc, "cannot create buffered reads-file for lane '$(lane)' / chunk '$(chunk)'",
                                          "lane=%S,chunk=%d", l->name, l->chunk ) );
            }
            else
            {
                KFileRelease( l->reads );
                l->reads = buffered;
            }
        }

        if ( rc == 0 && opts->comp != oc_none )
        {

            KFile * compressed = l->reads;
            if ( opts->comp == oc_bzip )
            {
                rc = KFileMakeBzip2ForWrite ( &compressed, l->reads );
            }
            else if ( opts->comp == oc_gzip )
            {
                rc = KFileMakeGzipForWrite ( &compressed, l->reads );
            }
            if ( rc != 0 )
            {
                (void)PLOGERR( klogErr, ( klogErr, rc, "cannot create bzip reads-file for lane '$(lane)' / chunk '$(chunk)'",
                                          "lane=%S,chunk=%d", l->name, l->chunk ) );
            }
            else
            {
                KFileRelease( l->reads );
                l->reads = compressed;
            }
        }

        if ( rc == 0 && opts->use_queue )
        {
            KFile * qf;
            rc  = KQueueFileMakeWrite ( &qf, l->reads, opts->qbytes, opts->qblock, opts->qtimeout );
            if ( rc != 0 )
            {
                (void)PLOGERR( klogErr, ( klogErr, rc, "cannot create background writer for lane '$(lane)' / chunk '$(chunk)'",
                                          "lane=%S,chunk=%d", l->name, l->chunk ) );
            }
            else
            {
                KFileRelease( l->reads );
                l->reads = qf;
            }
        }

    }

    if ( rc == 0 )
    {
        rc = write_header( opts, lookup, l );
    }

    return rc;
}
Esempio n. 3
0
rc_t init_out_redir( out_redir * self, out_redir_mode_t mode, const char * filename, size_t bufsize )
{
    rc_t rc;
    KFile *output_file;

    if ( filename != NULL )
    {
        KDirectory *dir;
        rc = KDirectoryNativeDir( &dir );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
        else
        {
            rc = KDirectoryCreateFile ( dir, &output_file, false, 0664, kcmInit, "%s", filename );
            KDirectoryRelease( dir );
        }
    }
    else
        rc = KFileMakeStdOut ( &output_file );

    if ( rc == 0 )
    {
        KFile *temp_file;

        /* wrap the output-file in compression, if requested */
        switch ( mode )
        {
            case orm_gzip  : rc = KFileMakeGzipForWrite( &temp_file, output_file ); break;
            case orm_bzip2 : rc = KFileMakeBzip2ForWrite( &temp_file, output_file ); break;
            case orm_uncompressed : break;
        }
        if ( rc == 0 )
        {
            if ( mode != orm_uncompressed )
            {
                KFileRelease( output_file );
                output_file = temp_file;
            }

            /* wrap the output/compressed-file in buffering, if requested */
            if ( bufsize != 0 )
            {
                rc = KBufFileMakeWrite( &temp_file, output_file, false, bufsize );
                if ( rc == 0 )
                {
                    KFileRelease( output_file );
                    output_file = temp_file;
                }
            }

            if ( rc == 0 )
            {
                self->kfile = output_file;
                self->org_writer = KOutWriterGet();
                self->org_data = KOutDataGet();
                self->pos = 0;
                rc = KOutHandlerSet( out_redir_callback, self );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "KOutHandlerSet() failed" );
            }
        }
    }
    return rc;
}