Logo Search packages:      
Sourcecode: tardy version File versions  Download package

void tar_output_filter_gzip::write_data_padding (  )  [virtual]

The write_data_padding is used to write padding to bring the output stream to a suitable byte multiple. Must be called exactly once for each file, after all the data has been written.

Reimplemented from tar_output_filter.

Definition at line 199 of file gzip.cc.

References crc, drop_dead(), hdr, tar_output::nfatal(), outbuf, pass_through, stream, temp_filename, temp_fp, rcstring::to_c_string(), tar_output_filter::write_data(), tar_output_filter::write_data_padding(), tar_output_filter::write_header(), and tar_output_filter::write_header_padding().

{
    if (!pass_through)
    {
      FILE *fp = (FILE *)temp_fp;

      /*
       * finish sending the compressed stream
       */
      stream.avail_in = 0; /* should be zero already anyway */
      if (stream.avail_out == 0)
      {
          fwrite(outbuf, 1, Z_BUFSIZE, fp);
          if (ferror(fp))
            nfatal("write %s", temp_filename.to_c_string());
          stream.next_out = outbuf;
          stream.avail_out = Z_BUFSIZE;
      }
      for (;;)
      {
          int err = deflate(&stream, Z_FINISH);
          if (err < 0)
            drop_dead(err);
          size_t len = Z_BUFSIZE - stream.avail_out;
          if (!len)
            break;
          fwrite(outbuf, len, 1, fp);
          if (ferror(fp))
            nfatal("write %s", temp_filename.to_c_string());
          stream.next_out = outbuf;
          stream.avail_out = Z_BUFSIZE;
      }

      /*
       * and the trailer
       */
      put_long(fp, crc);
      put_long(fp, stream.total_in);
      fflush(fp);
      if (ferror(fp))
          nfatal("write %s", temp_filename.to_c_string());

      /*
       * Clean up any resources we were using.
       */
      if (stream.state != NULL)
          deflateEnd(&stream);

      //
        // Now we have the temporary file, we know the size of the
        // compressed data, so we are able to write the tar file header
        // for the compressed form into the archive.
      //
      tar_header nhdr = hdr;
      nhdr.type = tar_header::type_normal_gzipped;
      nhdr.size = ftell(fp);
      tar_output_filter::write_header(nhdr);
      tar_output_filter::write_header_padding();

      //
      // Transfer the data from the temporary file into the archive.
      //
      rewind(fp);
      for (long opos = 0; opos < nhdr.size;)
      {
          unsigned long ret;
          unsigned long nbytes = nhdr.size - opos;
          if (nbytes > Z_BUFSIZE)
            nbytes = Z_BUFSIZE;
          ret = fread(outbuf, 1, nbytes, fp);
          if (ret != nbytes)
            nfatal("read %s", temp_filename.to_c_string());
          tar_output_filter::write_data(outbuf, nbytes);
          opos += nbytes;
      }
      fclose(fp);
      temp_fp = 0;
      unlink(temp_filename.to_c_string());

      //
      // Go back to pass through mode (the default).
      //
      pass_through = true;
    }

    //
    // Write the data padding to the deeper file.
    //
    tar_output_filter::write_data_padding();
}


Generated by  Doxygen 1.6.0   Back to index