IContentAsyncReadAsync Method
IT Hit WebDAV Classes Reference
Reads the file content from the repository and writes it to the specified stream.
Namespace:
ITHit.Server
Assembly:
ITHit.Server (in ITHit.Server.dll) Version: 11.3.10719
Syntax Task ReadAsync(
Stream output,
long startIndex,
long count
)
Task ReadAsync(
Stream output,
long startIndex,
long count
)
Function ReadAsync (
output As Stream,
startIndex As Long,
count As Long
) As Task
Function ReadAsync (
output As Stream,
startIndex As Long,
count As Long
) As Task
Task^ ReadAsync(
Stream^ output,
long long startIndex,
long long count
)
Task^ ReadAsync(
Stream^ output,
long long startIndex,
long long count
)
abstract ReadAsync :
output : Stream *
startIndex : int64 *
count : int64 -> Task
abstract ReadAsync :
output : Stream *
startIndex : int64 *
count : int64 -> Task
Parameters
- output
- Type: System.IOStream
Output stream. - startIndex
- Type: SystemInt64
The zero-bazed byte offset in file content at which to begin copying bytes to
the output stream. - count
- Type: SystemInt64
The number of bytes to be written to the output stream.
Return Value
Type:
Task .
Exceptions Remarks
By default ASP.NET buffers content on server side before sending output. You must turn off buffering to
eliminate keeping entire file content in memory before sending:
HttpContext.Current.Response.BufferOutput = false;
Client application can request only a part of a file specifying Range header. Download managers
may use this header to download single file using several threads at a time.
Examples The code below is part of 'WebDAVServer.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.
public virtual async Task ReadAsync(Stream output, long startIndex, long count)
{
HttpContext.Current.Server.ScriptTimeout = int.MaxValue;
if (ContainsDownloadParam(context.Request.RawUrl))
{
AddContentDisposition(Name);
}
byte[] buffer = new byte[bufSize];
using (FileStream fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
{
fileStream.Seek(startIndex, SeekOrigin.Begin);
int bytesRead;
int toRead = (int)Math.Min(count, bufSize);
if (toRead <= 0)
{
return;
}
try
{
bytesRead = await fileStream.ReadAsync(buffer, 0, toRead);
while (bytesRead > 0)
{
await output.WriteAsync(buffer, 0, bytesRead);
count -= bytesRead;
bytesRead = await fileStream.ReadAsync(buffer, 0, toRead);
}
}
catch (HttpException)
{
}
}
}
Public Overridable Async Function ReadAsync(output As Stream, startIndex As Long, count As Long) As Task Implements IContentAsync.ReadAsync
HttpContext.Current.Server.ScriptTimeout = Integer.MaxValue
If ContainsDownloadParam(context.Request.RawUrl) Then
AddContentDisposition(Name)
End If
Dim buffer As Byte() = New Byte(1048575) {}
Using fileStream As FileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read)
fileStream.Seek(startIndex, SeekOrigin.Begin)
Dim bytesRead As Integer
Dim toRead As Integer = CInt(Math.Min(count, bufSize))
If toRead <= 0 Then
Return
End If
Try
bytesRead = Await fileStream.ReadAsync(buffer, 0, toRead)
While bytesRead > 0
Await output.WriteAsync(buffer, 0, bytesRead)
count -= bytesRead
bytesRead = Await fileStream.ReadAsync(buffer, 0, toRead)
End While
Catch __unusedHttpException1__ As HttpException
End Try
End Using
End Function
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also