Ejemplo n.º 1
0
        private static async Task WritePartToResponse(Kooboo.IndexedDB.FilePart part, HttpResponseFeature Res)
        {
            long offset = part.BlockPosition + part.RelativePosition;

            byte[] buffer      = new byte[8096];
            long   totalToSend = part.Length;
            int    count       = 0;

            Res.Headers["Content-Length"] = totalToSend.ToString();

            long bytesRemaining = totalToSend;

            var stream = Kooboo.IndexedDB.StreamManager.OpenReadStream(part.FullFileName);

            stream.Position = offset;

            while (bytesRemaining > 0)
            {
                try
                {
                    if (bytesRemaining <= buffer.Length)
                    {
                        count = await stream.ReadAsync(buffer, 0, (int)bytesRemaining);
                    }
                    else
                    {
                        count = await stream.ReadAsync(buffer, 0, buffer.Length);
                    }

                    if (count == 0)
                    {
                        return;
                    }

                    await Res.Body.WriteAsync(buffer, 0, count);

                    bytesRemaining -= count;
                }
                catch (IndexOutOfRangeException)
                {
                    await Res.Body.FlushAsync();

                    return;
                }
                finally
                {
                    await Res.Body.FlushAsync();
                }
            }
        }
Ejemplo n.º 2
0
            private static async Task WritePartToResponse(Kooboo.IndexedDB.FilePart part, IHttpResponseFeature Res)
            {
                long offset = part.BlockPosition + part.RelativePosition;
                //byte[] buffer = new byte[209715200];
                long totalToSend = part.Length;

                Res.Headers["Content-Length"] = totalToSend.ToString();

                var stream = Kooboo.IndexedDB.StreamManager.OpenReadStream(part.FullFileName);

                stream.Position = offset;

                try
                {
                    await stream.ChunkCopyAsync(Res.Body, totalToSend);
                }
                catch (IndexOutOfRangeException)
                {
                }
                finally
                {
                    await Res.Body.FlushAsync();
                }
            }