如何将此文件连接函数从 Delphi 移植到 Ruby
我得到了这个 delphi 函数来连接文件:
procedure Join(Main_FileName, Hidden_Filename : string);
var
MainFile : TFileStream;
HiddenFile : TFileStream;
SizeOfFile : Cardinal;
SearchWord : string[10];
begin
MainFile := TFileStream.Create(Main_FileName, fmOpenReadWrite or fmShareDenyWrite);
try
SizeOfFile := MainFile.Size;
HiddenFile := TFileStream.Create(Hidden_Filename, fmOpenRead or fmShareDenyNone);
try
MainFile.Seek(0, soFromEnd);
MainFile.CopyFrom(HiddenFile, 0);
MainFile.Seek(0, soFromEnd);
finally
HiddenFile.Free;
end;
SearchWord := IntToStr(SizeOfFile) + #0;
MainFile.Seek(0, soFromEnd);
MainFile.WriteBuffer(SearchWord, SizeOf(SearchWord));
finally
MainFile.Free;
end;
end;
并且需要将其移植到 ruby 中。 创建的文件应该与这个delphi split函数兼容: (仅存在于delphi中,不需要ruby端口)
procedure Split(Main_FileName, NewFromMain_Filename : string);
var
MainFile : TFileStream;
SplitFile : TFileStream;
HelpStr : string[10];
GetSize : integer;
begin
MainFile := TFileStream.create(Main_FileName, fmOpenReadWrite or fmShareDenyWrite);
try
SplitFile := TFileStream.Create(NewFromMain_Filename, fmCreate or fmShareDenyNone);
try
MainFile.Position := MainFile.Size - 11;
MainFile.Read(HelpStr, 10);
GetSize := StrToInt(HelpStr);
MainFile.Position := GetSize;
SplitFile.CopyFrom(MainFile, MainFile.Size-GetSize);
SplitFile.Size := SplitFile.Size - 11;
MainFile.Size := GetSize;
finally
SplitFile.Free;
end;
finally
MainFile.Free;
end;
end;
delphi函数的来源来自这里: http://www.delphi-treff.de/tipps/ dateienverzeichnisse/dateioperationen/dateien-miteinander-verschmelzen/
I got this delphi function to join files:
procedure Join(Main_FileName, Hidden_Filename : string);
var
MainFile : TFileStream;
HiddenFile : TFileStream;
SizeOfFile : Cardinal;
SearchWord : string[10];
begin
MainFile := TFileStream.Create(Main_FileName, fmOpenReadWrite or fmShareDenyWrite);
try
SizeOfFile := MainFile.Size;
HiddenFile := TFileStream.Create(Hidden_Filename, fmOpenRead or fmShareDenyNone);
try
MainFile.Seek(0, soFromEnd);
MainFile.CopyFrom(HiddenFile, 0);
MainFile.Seek(0, soFromEnd);
finally
HiddenFile.Free;
end;
SearchWord := IntToStr(SizeOfFile) + #0;
MainFile.Seek(0, soFromEnd);
MainFile.WriteBuffer(SearchWord, SizeOf(SearchWord));
finally
MainFile.Free;
end;
end;
And need to port this in ruby.
The created file should compatible with this delphi split function:
(Exists in delphi only no ruby port needed)
procedure Split(Main_FileName, NewFromMain_Filename : string);
var
MainFile : TFileStream;
SplitFile : TFileStream;
HelpStr : string[10];
GetSize : integer;
begin
MainFile := TFileStream.create(Main_FileName, fmOpenReadWrite or fmShareDenyWrite);
try
SplitFile := TFileStream.Create(NewFromMain_Filename, fmCreate or fmShareDenyNone);
try
MainFile.Position := MainFile.Size - 11;
MainFile.Read(HelpStr, 10);
GetSize := StrToInt(HelpStr);
MainFile.Position := GetSize;
SplitFile.CopyFrom(MainFile, MainFile.Size-GetSize);
SplitFile.Size := SplitFile.Size - 11;
MainFile.Size := GetSize;
finally
SplitFile.Free;
end;
finally
MainFile.Free;
end;
end;
Source of the delphi functions in from here:
http://www.delphi-treff.de/tipps/dateienverzeichnisse/dateioperationen/dateien-miteinander-verschmelzen/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Ruby 方式 - 简短、可读且简单:
没有检查它的拆分工作,没有 delphi
Here is the Ruby way - short, readable and easy:
didn't check it split works, have no delphi