Пример #1
0
        protected override void Build(IHttpStreamable httpStream, bool prepare)
        {
            if (prepare)
            {
                return;
            }
            using (FileStream fis = new FileStream(fileLink.Path, FileMode.Open)) {
                int    bytesRead = -1;
                byte[] buffer    = new byte[HttpConfig.ChunkSize];

                while ((bytesRead = fis.Read(buffer, bytesRead, buffer.Length)) != -1)
                {
                    httpStream.WriteUnderlying(buffer, 0, bytesRead);
                }
                httpStream.FlushUnderlying();
            }
        }
Пример #2
0
        private void WriteFile(IHttpStreamable httpStream, FileLink fileLink)
        {
            if (Chunked)
            {
                ChunkHandler.WriteChunk(httpStream);
                httpStream.FlushUnderlying();

                if (ChunkHandler.IsFinished)
                {
                    ChunkHandler.Dispose();
                }
                return;
            }
            using (FileStream fis = new FileStream(fileLink.Path, FileMode.Open)) {
                int    bytesRead = -1;
                byte[] buffer    = new byte[HttpConfig.ChunkSize];

                while ((bytesRead = fis.Read(buffer)) != -1)
                {
                    httpStream.WriteUnderlying(buffer, 0, bytesRead);
                }
                httpStream.FlushUnderlying();
            }
        }