4

これは、 https://forums.embarcadero.com/message.jspa? messageID= 219481から取得したコードスニペットです。

if FileExists(dstFile) then
begin
  Fs := TFileStream.Create(dstFile, fmOpenReadWrite);
  try
    Fs.Seek(Max(0, Fs.Size-1024), soFromBeginning);
    // alternatively:
    // Fs.Seek(-1024, soFromEnd);
    Http.Request.Range := IntToStr(Fs.Position) + '-';
    Http.Get(Url, Fs);
  finally
    Fs.Free;
  end;
end;

正確にオフセットされているものと、プレースホルダーにMax(0、Fs.Size-1024)が含まれている理由、および以下に移動した場合(コード内)がわかりません

// alternatively:
    // Fs.Seek(-1024, soFromEnd);

'-1024'とは正確には何ですか...なぜ常に1024/-1024を使用するのですか?オフセットペースホルダーの作業ではfs.sizeだけで(一時停止の再開をサポートしてダウンロードを管理するようにしています)、上記のコードでtfilestreamをtmemmorystreamに置き換えると、プログラムに影響がありますか?

重要な場合:私はd2007とd2010を使用します

4

2 に答える 2

6

ファイルの末尾から1024(または、ファイルがまだそれほど大きくない場合は0)を探しているようです。それはすべて、送信を再開することと関係があります。ファイルの終わりが壊れていることがわかります。がらくたを切り取り(または0からやり直して)、悪い後に良いデータを追加しないようにします。

例え:あなたは氷の城を建てています。暗くなり、一晩で着氷性の雨が降ります。翌日、あなたはチェーンソーを手に入れ、1インチのクラッドを切り落とし、きれいな氷を露出させました。ここから構築を開始します。

于 2010-06-21T13:08:11.540 に答える
4

Since this is trying to create a download manager that can stop and resume downloads, the idea here is that when you resume, it wants to step back a little bit and re-request some of the data that was previously sent just in case the disconnect was caused by an error that caused the data received to be corrupted. Most download managers that I've seen will step back by at least 4 KB; looks like this one is only doing 1 KB.

If you put fs.Size alone in the placeholder then it wouldn't step back at all, which could leave you open to the possibility of corrupt data.

And replacing TFileStream with TMemoryStream would mean that you're downloading to RAM instead of to disc, and if the computer crashes or loses power or your app crashes somehow, all the progress is lost. So that's not a good idea. Also, downloading to RAM limits the size of your download to the available size of your address space, which would make downloading large files (ISOs of DVDs, for example) either impossible or at least much more difficult than it needs to be.

于 2010-06-21T13:10:09.820 に答える