I rozwiązać tworząc klasę owijania nazwie WebStreamWithLenght (seek metoda nie jest realizowany, bo nie jest to potrzebne)
należy go używać jak to
WebRequest req = HttpWebRequest.Create(link);
WebResponse res = req.GetResponse();
var stream = res.GetResponseStream();
var streamWithLenght = new WebStreamWithLenght(stream, res.ContentLength);
public class WebStreamWithLenght : Stream
{
long _Lenght;
Stream _Stream;
long _Position;
public WebStreamWithLenght(Stream stream, long lenght)
{
_Stream = stream;
_Lenght = lenght;
}
public override bool CanRead
{
get { return _Stream.CanRead; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return _Stream.CanWrite; }
}
public override void Flush()
{
_Stream.Flush();
}
public override long Length
{
get { return _Lenght; }
}
public override long Position { get; set; }
public override int Read(byte[] buffer, int offset, int count)
{
var result = _Stream.Read(buffer, offset, count);
Position += count;
return result;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
_Lenght = value;
}
public override void Write(byte[] buffer, int offset, int count)
{
Write(buffer, offset, count);
}
}
zrobiłem test w PHP gdzie Ustawiłem długość zawartości ([kod na pastebin] (http://pastebin.com/CX7imFKr)), nie jestem pewien, czy zrobiłem to dobrze, i wciąż mam niedostrzegalny strumień ... hmm ... Spróbuję prawdziwe pobieranie, może z download.com później ... –
Strumień 'WebResponse.GetResponseStream' jest niedostępny. Jest to strumień tylko do odczytu i do odczytu. Ale nagłówek 'ContentLength', jeśli jest ustawiony, jest zwykle niezawodny. Nie powinieneś szukać. –