bool do_copy() // Copy the data. Return true on success, false on failure. { if (m_done_copy) { assert(0); log_error("gameswf::tools::copy_helper() already done copy\n"); return false; } m_done_copy = true; int current_in_pos = m_in->get_position(); int bytes_to_copy = current_in_pos - m_initial_in_pos; if (bytes_to_copy > 0) { m_in->set_position(m_initial_in_pos); int bytes_copied = m_out->copy_bytes(m_in, bytes_to_copy); if (bytes_copied != bytes_to_copy) { m_in->set_position(current_in_pos); // fixup return false; } assert(m_in->get_position() == current_in_pos); return true; } else { log_error("gameswf::tools::copy_helper asked to copy %d bytes\n", bytes_to_copy); return false; } }
void rewind_unused_bytes() // If we have unused bytes in our input buffer, rewind // to before they started. { if (m_zstream.avail_in > 0) { int pos = m_in->get_position(); int rewound_pos = pos - m_zstream.avail_in; assert(pos >= 0); assert(pos >= m_initial_stream_pos); assert(rewound_pos >= 0); assert(rewound_pos >= m_initial_stream_pos); m_in->set_position(rewound_pos); } }
void reset() // Discard current results and rewind to the beginning. // Necessary in order to seek backwards. { m_error = 0; m_at_eof = 0; int err = inflateReset(&m_zstream); if (err != Z_OK) { m_error = 1; return; } m_zstream.next_in = 0; m_zstream.avail_in = 0; m_zstream.next_out = 0; m_zstream.avail_out = 0; // Rewind the underlying stream. m_in->set_position(m_initial_stream_pos); m_logical_stream_pos = 0; }