23 t_size remaining = p_bytes;
27 if (delta > remaining) delta = remaining;
43 assert(p_backlogdepth <=
m_depth);
44 assert(p_backlogdepth >= p_bytes);
48 t_size remaining = p_bytes;
54 if (delta > remaining) delta = remaining;
83 m_position = m_position_base = 0;
84 m_size = m_file->get_size(p_abort);
88 if (p_reader.
is_valid() && p_reader->is_remote() && p_buffer_size > 0) {
90 instance->initialize(p_reader,p_buffer_size,p_abort);
98 if (m_position > m_position_base + pfc::max_t<t_size>(
m_buffer.get_max_depth(),
backread_on_seek) && m_file->can_seek()) {
103 m_file->seek(target,p_abort);
104 m_position_base = target;
108 while(m_position > m_position_base) {
109 enum {tempsize = 1024};
111 t_size delta = (
t_size) pfc::min_t<t_filesize>(tempsize,m_position - m_position_base);
113 bytes_read = m_file->read(temp,delta,p_abort);
115 m_position_base += bytes_read;
117 if (bytes_read < delta) {
126 if (m_position < m_position_base) {
127 if (m_position_base - m_position > (
t_filesize)
m_buffer.get_depth())
throw exception_io_seek_out_of_range();
128 t_size backread_depth = (
t_size) (m_position_base - m_position);
129 t_size delta = pfc::min_t<t_size>(backread_depth,p_bytes-done);
130 m_buffer.read(backread_depth,targetptr,delta);
139 bytes_read = m_file->read(targetptr+done,p_bytes-done,p_abort);
141 m_buffer.write(targetptr+done,bytes_read);
144 m_position += bytes_read;
145 m_position_base += bytes_read;
162 assert(m_position_base >=
m_buffer.get_depth());
165 if (m_size !=
filesize_invalid && p_position > m_size)
throw exception_io_seek_out_of_range();
169 if (p_position < lowest) {
170 if (m_file->can_seek()) {
175 if (target > delta) target -= delta;
177 m_file->seek(target,p_abort);
178 m_position_base = target;
182 m_file->reopen(p_abort);
187 m_position = p_position;
203 return m_file->get_timestamp(p_abort);
207 if (m_position_base -
m_buffer.get_depth() == 0) {
210 m_position = m_position_base = 0;
212 m_file->reopen(p_abort);
218 return m_file->is_remote();
const t_item * get_ptr() const
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
t_size get_max_depth() const
void seek(HANDLE p_handle, t_sfilesize p_position, file::t_seek_mode p_mode)
t_filesize get_position(abort_callback &p_abort)
bool get_content_type(pfc::string_base &p_out)
pfc::array_t< t_uint8 > m_buffer
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
t_filesize get_size(abort_callback &p_abort)
void write(const void *p_buffer, t_size p_bytes)
static void g_seekabilize(service_ptr_t< file > &p_reader, t_size p_buffer_size, abort_callback &p_abort)
void on_idle(abort_callback &p_abort)
t_filetimestamp get_timestamp(abort_callback &p_abort)
void set_size(t_size p_size)
void reopen(abort_callback &p_abort)
t_uint64 t_filetimestamp
Type used for file timestamp related variables. 64-bit value representing the number of 100-nanosecon...
t_uint64 t_filesize
Type used for file size related variables.
void read(t_size p_backlogdepth, void *p_buffer, t_size p_bytes) const
void seek(t_filesize p_position, abort_callback &p_abort)
void initialize(t_size p_size)
t_size read(void *p_buffer, t_size p_bytes, abort_callback &p_abort)
void initialize(service_ptr_t< file > p_base, t_size p_buffer_size, abort_callback &p_abort)