Esempio n. 1
0
void tag_processor_id3v2::g_remove_ex(tag_write_callback & p_callback,const service_ptr_t<file> & p_file,t_uint64 & p_size_removed,abort_callback & p_abort)
{
	p_file->ensure_seekable();

	t_filesize len;
	
	len = p_file->get_size(p_abort);

	if (len == filesize_invalid) throw exception_io_no_length();
	
	p_file->seek(0,p_abort);
	
	t_uint64 offset;
	g_multiskip(p_file,offset,p_abort);
	
	if (offset>0 && offset<len)
	{
		len-=offset;
		service_ptr_t<file> temp;
		if (p_callback.open_temp_file(temp,p_abort)) {
			file::g_transfer_object(p_file,temp,len,p_abort);
		} else {
			if (len > 16*1024*1024) filesystem::g_open_temp(temp,p_abort);
			else filesystem::g_open_tempmem(temp,p_abort);
			file::g_transfer_object(p_file,temp,len,p_abort);
			p_file->seek(0,p_abort);
			p_file->set_eof(p_abort);
			temp->seek(0,p_abort);
			file::g_transfer_object(temp,p_file,len,p_abort);
		}
	}
	p_size_removed = offset;
}
Esempio n. 2
0
void file::g_transfer_object(service_ptr_t<file> p_src,service_ptr_t<file> p_dst,t_filesize p_bytes,abort_callback & p_abort) {
	if (p_bytes > 1024) /* don't bother on small objects */ 
	{
		t_filesize oldsize = p_dst->get_size(p_abort);
		if (oldsize != filesize_invalid) {
			t_filesize newpos = p_dst->get_position(p_abort) + p_bytes;
			if (newpos > oldsize) p_dst->resize(newpos ,p_abort);
		}
	}
	g_transfer_object(pfc::implicit_cast<stream_reader*>(p_src.get_ptr()),pfc::implicit_cast<stream_writer*>(p_dst.get_ptr()),p_bytes,p_abort);
}
bool load_feature_list_from_json_file(pfc::list_base_t<feature_handle_ptr> &p_list, const service_ptr_t<file> &p_file, abort_callback &p_abort)
{
	t_filesize size = p_file->get_size(p_abort);

	pfc::string8 json;
	{
		pfc::string_buffer buffer(json, size);
		p_file->read_object(buffer, size, p_abort);
	}

	return load_feature_list_from_json_string(p_list, json);
}
Esempio n. 4
0
static void process_fullbuffer(service_ptr_t<file> & p_file,const char * p_path,t_filesize p_fullbuffer,abort_callback & p_abort) {
	if (p_fullbuffer > 0) {
		if (p_file.is_empty()) {
			service_ptr_t<filesystem> fs;
			if (filesystem::g_get_interface(fs,p_path)) {
				fs->open(p_file,p_path,filesystem::open_mode_read,p_abort);
			}
		}

		if (p_file.is_valid()) {
			t_filesize size = p_file->get_size(p_abort);
			if (size != filesize_invalid && size <= p_fullbuffer) {
				service_ptr_t<file> l_file_buffered;
				if (reader_membuffer_mirror::g_create(l_file_buffered,p_file,p_abort)) {
					p_file = l_file_buffered;
				}
			}
		}
	}
}
Esempio n. 5
0
	void read_v2(const service_ptr_t<file> & p_file,abort_callback & p_abort,pfc::string_base & p_out,bool & is_utf8, bool forceUTF8) {
		p_out.reset();
		p_file->reopen( p_abort );
		
		pfc::array_t<char> mem;
		t_filesize size64;
		size64 = p_file->get_size(p_abort);
		if (size64 == filesize_invalid)//typically HTTP
		{
			pfc::string8 ansitemp;
			t_size done;
			enum { delta = 1024 * 64, max = 1024 * 512 };

			if ( forceUTF8 ) {
				is_utf8 = true;
			} else {
				is_utf8 = false;
				char temp[3];
				done = p_file->read(temp, 3, p_abort);
				if (done != 3)
				{
					if (done > 0) p_out = pfc::stringcvt::string_utf8_from_ansi(temp, done);
					return;
				}
				if (!memcmp(utf8_header, temp, 3)) is_utf8 = true;
				else ansitemp.add_string(temp, 3);
			}

			mem.set_size(delta);
			
			for(;;)
			{
				done = p_file->read(mem.get_ptr(),delta,p_abort);
				if (done > 0)
				{
					if (is_utf8) p_out.add_string(mem.get_ptr(),done);
					else ansitemp.add_string(mem.get_ptr(),done);
				}
				if (done < delta) break;
			}

			if (!is_utf8)
			{
				p_out = pfc::stringcvt::string_utf8_from_ansi(ansitemp);
			}

			return;
		}
		else
		{
			if (size64>1024*1024*128) throw exception_io_data();//hard limit
			t_size size = pfc::downcast_guarded<t_size>(size64);
			mem.set_size(size+1);
			char * asdf = mem.get_ptr();
			p_file->read_object(asdf,size,p_abort);
			asdf[size]=0;
			if ( forceUTF8 ) {
				is_utf8 = true;
				p_out = asdf;
			} else if (size>3 && !memcmp(utf8_header,asdf,3)) {
				is_utf8 = true; 
				p_out.add_string(asdf+3); 
			} else {
				is_utf8 = false;
				p_out = pfc::stringcvt::string_utf8_from_ansi(asdf);
			}
			return;
		}
	}