svn_error_t * svn_diff_output_binary(svn_stream_t *output_stream, svn_stream_t *original, svn_stream_t *latest, svn_cancel_func_t cancel_func, void *cancel_baton, apr_pool_t *scratch_pool) { apr_file_t *original_apr; svn_filesize_t original_full; svn_filesize_t original_deflated; apr_file_t *latest_apr; svn_filesize_t latest_full; svn_filesize_t latest_deflated; apr_pool_t *subpool = svn_pool_create(scratch_pool); SVN_ERR(create_compressed(&original_apr, &original_full, &original_deflated, original, cancel_func, cancel_baton, scratch_pool, subpool)); svn_pool_clear(subpool); SVN_ERR(create_compressed(&latest_apr, &latest_full, &latest_deflated, latest, cancel_func, cancel_baton, scratch_pool, subpool)); svn_pool_clear(subpool); SVN_ERR(svn_stream_puts(output_stream, "GIT binary patch" APR_EOL_STR)); /* ### git would first calculate if a git-delta latest->original would be shorter than the zipped data. For now lets assume that it is not and just dump the literal data */ SVN_ERR(write_literal(latest_full, svn_stream_from_aprfile2(latest_apr, FALSE, subpool), output_stream, cancel_func, cancel_baton, scratch_pool)); svn_pool_clear(subpool); SVN_ERR(svn_stream_puts(output_stream, APR_EOL_STR)); /* ### git would first calculate if a git-delta original->latest would be shorter than the zipped data. For now lets assume that it is not and just dump the literal data */ SVN_ERR(write_literal(original_full, svn_stream_from_aprfile2(original_apr, FALSE, subpool), output_stream, cancel_func, cancel_baton, scratch_pool)); svn_pool_destroy(subpool); return SVN_NO_ERROR; }
/** * cdk_pkt_write: * @out: the output stream handle * @pkt: the packet itself * * Write the contents of @pkt into the @out stream. * Return 0 on success. **/ cdk_error_t cdk_pkt_write (cdk_stream_t out, cdk_packet_t pkt) { cdk_error_t rc; if (!out || !pkt) return CDK_Inv_Value; _cdk_log_debug ("write packet pkttype=%d\n", pkt->pkttype); switch (pkt->pkttype) { case CDK_PKT_LITERAL: rc = write_literal (out, pkt->pkt.literal, pkt->old_ctb); break; case CDK_PKT_ONEPASS_SIG: rc = write_onepass_sig (out, pkt->pkt.onepass_sig); break; case CDK_PKT_MDC: rc = write_mdc (out, pkt->pkt.mdc); break; case CDK_PKT_PUBKEY_ENC: rc = write_pubkey_enc (out, pkt->pkt.pubkey_enc, pkt->old_ctb); break; case CDK_PKT_SIGNATURE: rc = write_signature (out, pkt->pkt.signature, pkt->old_ctb); break; case CDK_PKT_PUBLIC_KEY: rc = write_public_key (out, pkt->pkt.public_key, 0, pkt->old_ctb); break; case CDK_PKT_PUBLIC_SUBKEY: rc = write_public_key (out, pkt->pkt.public_key, 1, pkt->old_ctb); break; case CDK_PKT_COMPRESSED: rc = write_compressed (out, pkt->pkt.compressed); break; case CDK_PKT_SECRET_KEY: rc = write_secret_key (out, pkt->pkt.secret_key, 0, pkt->old_ctb); break; case CDK_PKT_SECRET_SUBKEY: rc = write_secret_key (out, pkt->pkt.secret_key, 1, pkt->old_ctb); break; case CDK_PKT_USER_ID: case CDK_PKT_ATTRIBUTE: rc = write_user_id (out, pkt->pkt.user_id, pkt->old_ctb, pkt->pkttype); break; default: rc = CDK_Inv_Packet; break; } if (DEBUG_PKT) _cdk_log_debug ("write_packet rc=%d pkttype=%d\n", rc, pkt->pkttype); return rc; }
/* definitions */ void *static_deflate(void *io_struct) { io *io_s = (io *) io_struct; prepare_input_output(io_s); cyclic_queue *cqbuff = new_cyclic_queue(LEN_SIZE_Q, false); write_static_header(io_s); byte buff[LEN_MAX]; size_t count = fread(buff, EL_SIZE, LEN_MAX, io_s->input); push_back_cyclic_queue(cqbuff, buff, count); byte front_b; size_t offset, length, last_count; while (!isempty_cyclic_queue(cqbuff)) { search_cyclic_queue(io_s->cqdict, cqbuff, &offset, &length); if (offset == 0 && length == 0) { front_b = front_cyclic_queue(cqbuff); write_literal(io_s, front_b); move_front_cyclic_queue(cqbuff, io_s->cqdict, 1); } else { write_pointer(io_s, length, offset); move_front_cyclic_queue(cqbuff, io_s->cqdict, length); } if (length == 0) length = 1; if (count < io_s->block_size) { if (count + length > io_s->block_size) length = count + length - io_s->block_size; last_count = fread(buff, EL_SIZE, length, io_s->input); push_back_cyclic_queue(cqbuff, buff, last_count); count += last_count; } } io_s->block_size = count; write_end_of_block(io_s); if (io_s->isfinal) byte_flush(io_s); delete_cyclic_queue(cqbuff); io_s->result = get_output_size(io_s); pthread_exit(NULL); }
static void write_block (void) { int lengths[32]; huf_table raw, dist, len; int i, j, k; for (i=0; i<32; i++) lengths[i] = 0; for (i=0; i<=ntuple; i++) lengths[length(tuples[i].rawlen)]++; build_huf (&raw, lengths); write_huf (&raw); for (i=0; i<32; i++) lengths[i] = 0; for (i=0; i<ntuple; i++) lengths[length(tuples[i].pos-1)]++; build_huf (&dist, lengths); write_huf (&dist); for (i=0; i<32; i++) lengths[i] = 0; for (i=0; i<ntuple; i++) lengths[length(tuples[i].len-2)]++; build_huf (&len, lengths); write_huf (&len); write_bits (ntuple+1, 16); k = blkstart; for (i=0; i<=ntuple; i++) { write_hval (&raw, tuples[i].rawlen); for (j=0; j<tuples[i].rawlen; j++) write_literal (blk[k++]); if (i == ntuple) break; write_hval (&dist, tuples[i].pos-1); write_hval (&len, tuples[i].len-2); k += tuples[i].len; } }
// save delta file void write_commands (FILE* fo, FILE* files[]) { unsigned char buf[4] = { 'r', 's', 0x02, '6' }; delta_chunk t_chunk; int parm1, parm2; int len1, len2; int cmd; fwrite(buf, 4, 1, fo); for (int i = 0 ; i < command_count; i++) { t_chunk = chunks[i]; switch (t_chunk.c_type) { case RS_KIND_END: buf[0] = 0; fwrite(buf, 1, 1, fo); break; case RS_KIND_COPY: parm1 = t_chunk.sf_pos; parm2 = t_chunk.len; len1 = get_parm_len(parm1); len2 = get_parm_len(parm2); switch (len1) { case 1: cmd = RS_OP_COPY_N1_N1; break; case 2: cmd = RS_OP_COPY_N2_N1; break; case 4: cmd = RS_OP_COPY_N4_N1; break; case 8: cmd = RS_OP_COPY_N8_N1; break; default: throw new int; } switch (len2) { case 1: cmd += 0; break; case 2: cmd += 1; break; case 4: cmd += 2; break; case 8: cmd += 3; break; default: throw new int; } buf[0] = (unsigned char) (cmd & 0xFF); fwrite(buf, 1, 1, fo); write_parm(fo, len1, parm1); write_parm(fo, len2, parm2); break; case RS_KIND_LITERAL: parm1 = t_chunk.len; len1 = get_parm_len(parm1); switch (len1) { case 1: cmd = RS_OP_LITERAL_N1; break; case 2: cmd = RS_OP_LITERAL_N2; break; case 4: cmd = RS_OP_LITERAL_N4; break; case 8: cmd = RS_OP_LITERAL_N8; break; default: throw new int; } buf[0] = (unsigned char) (cmd & 0xFF); fwrite(buf, 1, 1, fo); write_parm(fo, len1, parm1); write_literal(files[t_chunk.sf_id], fo, t_chunk.sf_pos, t_chunk.len); break; } } }