如何将此文件连接功能从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;
并且需要将其移植到红宝石中。 创建的文件应与此delphi拆分功能兼容: (仅存在于delphi中,不需要红宝石端口)
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/     
已邀请:
这是Ruby的方式-简短,易读且简单:
size = File.size(\"mainfile\")
File.open(\"mainfile\", \"ab\") {|mf|
  File.open(\"hiddenfile\", \"rb\") { |hf|
     mf.write(hf.read)
     mf.write(\"#{size}\\x0\".ljust(10))
  }
}
没有检查它是否可以拆分,没有delphi     

要回复问题请先登录注册