--- parser3/src/classes/file.C 2006/12/01 17:59:13 1.149 +++ parser3/src/classes/file.C 2007/02/07 15:50:32 1.151 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_FILE_C="$Date: 2006/12/01 17:59:13 $"; +static const char * const IDENT_FILE_C="$Date: 2007/02/07 15:50:32 $"; #include "pa_config_includes.h" @@ -160,7 +160,7 @@ static void copy_process_source( int nCount=0; do { unsigned char buffer[FILE_BUFFER_SIZE]; - nCount = read(from_file, buffer, sizeof(buffer)); + nCount = file_block_read(from_file, buffer, sizeof(buffer)); int written=write(to_file, buffer, nCount); if( written < 0 ) throw Exception(0, @@ -837,6 +837,8 @@ static void _sql(Request& r, MethodParam } static void _base64(Request& r, MethodParams& params) { + bool dynamic = !(&r.get_self() == file_class); + if ( dynamic ){ VFile& self=GET_SELF(r, VFile); if(params.count()) { // decode @@ -851,6 +853,12 @@ static void _base64(Request& r, MethodPa const char* encoded=pa_base64_encode(self.value_ptr(), self.value_size()); r.write_assign_lang(*new String(encoded, 0, true/*once ?param=base64(something) was needed*/)); } + } else { + // encode + const String& file_spec=params.as_string(0, "file name must be string"); + const char* encoded=pa_base64_encode(r.absolute(file_spec)); + r.write_assign_lang(*new String(encoded, 0, true/*once ?param=base64(something) was needed*/)); + } } static void _crc32(Request& r, MethodParams& params) { @@ -885,7 +893,7 @@ static void file_md5_file_action( int nCount=0; do { unsigned char buffer[FILE_BUFFER_SIZE]; - nCount = read(f, buffer, sizeof(buffer)); + nCount = file_block_read(f, buffer, sizeof(buffer)); if ( nCount ){ pa_MD5Update(&md5context, (const unsigned char*)buffer, nCount); } @@ -1000,7 +1008,8 @@ MFile::MFile(): Methoded("file") { // ^file::base64[string] << decode // ^file.base64[] << encode - add_native_method("base64", Method::CT_DYNAMIC, _base64, 0, 1); + // ^file:base64[file-name] << encode + add_native_method("base64", Method::CT_ANY, _base64, 0, 1); // ^file.crc32[] // ^file:crc32[file-name]