Zadanie przykładowe nr 3
|
|
Przeglądarka Zip'ów
Autor: Mateusz Henc
![]() |
![]() |
![]() |
![]() |
public void ProcessRequest(HttpContext context)
{
const int BUFFOR_SIZE = 8192;
string query = context.Request.QueryString["file"];
if (query == null || query==String.Empty)
return;
WebClient client = new WebClient();
try
{
using (Stream str = client.OpenRead(new Uri(query)))
{
byte[] buffer = new byte[BUFFOR_SIZE];
int count = 0;
while ((count = str.Read(buffer, 0, BUFFOR_SIZE)) > 0)
{
context.Response.OutputStream.Write(buffer, 0, count);
}
}
}
catch (Exception)
{ }
}
private void LoadStream(Stream stream)
{
List<ZipEntry> files = new List<ZipEntry>();
using (ZipInputStream zipInput = new ZipInputStream(stream))
{
ZipEntry entry = null;
while ((entry = zipInput.GetNextEntry()) != null)
if (entry.IsFile)
files.Add(entry);
}
}
private Stream GetFileStream(ZipEntry file)
{
using (ZipInputStream input = new ZipInputStream(Memory.Read()))
{
while (input.GetNextEntry().Name != file.Name) ;
MemoryStream str = new MemoryStream();
byte[] buff = new byte[App.BUFFOR_SIZE];
int count;
while ((count = input.Read(buff, 0, App.BUFFOR_SIZE)) > 0)
{
str.Write(buff, 0, count);
}
str.Position = 0;
return str;
}
}