procedure Base64EncFile(infilename, outfilename: string);
// copies file in infile to outfile. Uses file mapping to read, but regular
// Delphi "file" to write.
var
FileHandle: THandle;
MapHandle: THandle;
ViewPointer: Pointer;
outptr: Pointer;
outfile: file;
outsize: longint;
begin
FileHandle := CreateFile(Pchar(infilename), GENERIC_READ,
FILE_SHARE_READ or FILE_SHARE_WRITE,nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);
MapHandle := CreateFileMapping(FileHandle, nil, PAGE_READONLY, 0, 0, nil);
ViewPointer := MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0);
if ViewPointer <> nil then
try
Assign(outfile, outfilename);
rewrite(outfile, 1);
CryptBinaryToStringA(ViewPointer, GetFileSize(FileHandle, nil),
CRYPT_STRING_BASE64, nil, outsize);
GetMem(outptr, outsize);
CryptBinaryToStringA(ViewPointer, GetFileSize(FileHandle, nil),
CRYPT_STRING_BASE64, outptr, outsize);
BlockWrite(outfile, outptr^, outsize);
Close(outfile);
FreeMem(outptr);
finally
UnMapViewofFile(ViewPointer);
end;
CloseHandle(maphandle);
CloseHandle(FileHandle);
end;