コード例 #1
0
ファイル: rw.cpp プロジェクト: chen--oRanGe/xdeltalib
int f_local_freader::read_file (uchar_t * data, const uint32_t len)
{
	if (data == 0 || len == 0) {
		std::string errmsg ("Parameter(s) not correct");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}
#ifdef _WIN32
	if (f_handle_ == INVALID_HANDLE_VALUE) {
		std::string errmsg ("File not open.");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}
	uint32_t bytes;
	int result = ::ReadFile (f_handle_, data, len, (LPDWORD)&bytes, NULL);
	
	if (result == FALSE) {
		std::string errmsg = fmt_string ("Can't read file %s", f_name_.c_str ());
		THROW_XDELTA_EXCEPTION (errmsg);
	}

	return (int)bytes;
#else
	if (f_fd_ == -1) {
		std::string errmsg ("File not open.");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}
	return read (f_fd_, data, len);
#endif
}
コード例 #2
0
ファイル: rw.cpp プロジェクト: chen--oRanGe/xdeltalib
int f_local_fwriter::write_file (const uchar_t * data, const uint32_t length)
{
	uint32_t len = length;
	if (data == 0) {
		std::string errmsg ("Parameter(s) not correct");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}
	if (len == 0)
	    return 0;
	    
#ifdef _WIN32
	if (f_handle_ == INVALID_HANDLE_VALUE) {
		std::string errmsg ("File not open.");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}

	uint32_t dwWritten;
	while (true) {
		int result = ::WriteFile (f_handle_, data, (unsigned) len, (LPDWORD)(&dwWritten), 0);
		//TODO: check the dwWritten
		if (!result) {
			std::string errmsg = fmt_string ("Can't not write file %s.", f_name_.c_str ());
			THROW_XDELTA_EXCEPTION (errmsg);
		}
		
		if (dwWritten == len) {
			break;
		}
		else {
			len -= dwWritten;
			data += dwWritten;
		}
	}

	return len;
#else
	if (f_fd_ == -1) {
		std::string errmsg ("File not open.");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}
	return write (f_fd_, data, len);
#endif
}
コード例 #3
0
ファイル: inplace.cpp プロジェクト: ApusApp/xdeltalib
void in_place_reconstructor::start_hash_stream (const std::string & fname
								, const int32_t blk_len)
{
	reader_ = foperator_.create_reader (fname);
	if (reader_->exist_file ()) {
		reader_->open_file ();
	}
	else {
		foperator_.release (reader_);
		reader_ = 0;
	}

	writer_ = foperator_.create_writer (fname);
	if (writer_ == 0) {
		std::string errmsg = fmt_string ("Can't create file %s.", fname.c_str ());
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}

	writer_->open_file ();
	fname_ = fname;
	ftmpname_.clear ();
}
コード例 #4
0
ファイル: rw.cpp プロジェクト: chen--oRanGe/xdeltalib
static uint64_t get_file_size (const std::string & filename)
#endif
{
#ifdef _WIN32
	if (handle == INVALID_HANDLE_VALUE) {
		std::string errmsg ("File not open.");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}
	uint64_t filsiz;
	DWORD high, low;
	low = GetFileSize (handle, &high);
	filsiz = high;
	filsiz <<= 32;
	return (filsiz + low) ;
#else
	struct stat st;
	int ret = stat(filename.c_str (), &st);
	if (ret < 0) {
		std::string errmsg = fmt_string ("Can't not stat file %s.", filename.c_str ());
		THROW_XDELTA_EXCEPTION (errmsg);
	}
	return st.st_size;
#endif
}
コード例 #5
0
ファイル: fuzzysim.cpp プロジェクト: lipengyu/xdeltalib
std::string fuzzy::calc_digest () 
{
	fuzzy_state * ctx = fuzzy_new () ; 
	auto_fuzzy_state afs (ctx) ; 
	if (ctx == 0) 
		 THROW_XDELTA_EXCEPTION_NO_ERRNO ("Out of memory") ; 

	char_buffer<uchar_t> buff (BUFLEN);
	reader_.open_file () ; 
	while (true ) { 
		 int bytes = reader_.read_file (buff.begin (), (uint32_t)buff.size ()); 
		 if (bytes == 0 ) 
		 	 break ; 

		 if (0 != fuzzy_update (afs.ctx, buff.begin (), bytes)) 
		 	 THROW_XDELTA_EXCEPTION ("fuzzy update failed.") ; 
	} 
	char result [FUZZY_MAX_RESULT]; 
	if (0 != fuzzy_digest (afs.ctx, result, FUZZY_FLAG_ELIMSEQ)) 
		 THROW_XDELTA_EXCEPTION ("fuzzy digest failed.");
		 
	reader_.close_file () ; 
	return std::string(result) ; 
}