Kan man tanka ner början av en zipfil så man får vilka filer som ingår? (finns ju förresten prg som gör sånt... så hur gör man?) hmm, blev lite intresserad själv. Hittade inget specifikt men jag ger dig två länkar iallafall. kolla här: Roggan: ska försöka tyda den ;) Jag blev också lite intresserad av det här... Knappade ihop följande kod Skulle du kunna fixa en likadan funktion fast för att läsa lokala filer istället? (Får inte till addrange på File.OpenRead() :P) Så här? Så här?Zip-header eller nåt
Mr T @thomasa88.homeip.netSv: Zip-header eller nåt
Här är nån som har gjort det i vb, vet inte om det fungerar eller om du fattar nåt men där är väl principen iallafall:
http://groups.google.se/groups?hl=sv&lr=&ie=UTF-8&oe=UTF-8&selm=ezsZOGlNBHA.1444%40tkmsftngp03&rnum=8
Annars kan du ju alltid ladda ner ZipLib, där finns ju hela källkoden till ett zipprogram så där bör du kunna hitta nur du skall "parsa" fram vilka filer som finns:
http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspxSv: Zip-header eller nåt
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=25781&lngWId=1
förvisso ett vb6 prog.
'browsen' är baserad på min gamla kod(...This program is an update for the code that Rang3r posted...)
koden är redigt otäck , använde strängar istället för bytearrayer men men..
det ska väll inte vara _helt_ omöjligt att tyda den..
//RogerSv: Zip-header eller nåt
Arathorn: ska kolla på den med :)
Mr T @thomasa88.homeip.netSv: Zip-header eller nåt
<code>
using System;
using System.Net;
using System.Text;
using System.IO;
public class Test
{
public static void Main()
{
string url = "http://www.pellesoft.se/upload/program/prg00081.zip";
ZipEntry[] entries = GetZipEntries(url);
if (entries!=null) {
foreach(ZipEntry entry in entries)
Console.WriteLine(entry.Name + "\t\t" + entry.UncompressedSize);
}
Console.Read();
}
public static ZipEntry[] GetZipEntries(string url)
{
ZipEntry[] entries = null;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AddRange(-22);
WebResponse response = request.GetResponse();
BinaryReader br = new BinaryReader(response.GetResponseStream());
if (br.ReadInt32() == 0x06054b50)
{
br.ReadBytes(6);
entries = new ZipEntry[br.ReadInt16()];
int length = br.ReadInt32();
int offset = br.ReadInt32();
br.ReadBytes(2);
br.Close();
response.Close();
request = (HttpWebRequest)WebRequest.Create(url);
request.AddRange(offset, offset+length);
response = request.GetResponse();
br = new BinaryReader(response.GetResponseStream());
for(int i=0;i<entries.Length;i++)
{
if (br.ReadInt32() == 0x02014b50)
{
ZipEntry entry = new ZipEntry();
entry.Version = br.ReadInt16();
entry.VersionNeeded = br.ReadInt16();
entry.Bitflag = br.ReadInt16();
entry.CompressionMethod = br.ReadInt16();
entry.FileTime = br.ReadInt16();
entry.FileDate = br.ReadInt16();
entry.CRC32 = br.ReadInt32();
entry.CompressedSize = br.ReadInt32();
entry.UncompressedSize = br.ReadInt32();
entry.NameLength = br.ReadInt16();
entry.ExtraFieldSize = br.ReadInt16();
entry.FileCommentLength = br.ReadInt16();
entry.DiskNumberStart = br.ReadInt16();
entry.InternalFileAttributes = br.ReadInt16();
entry.ExternalFileAttributes = br.ReadInt32();
entry.RelativeOffset = br.ReadInt32();
entry.Name = Encoding.UTF8.GetString(br.ReadBytes(entry.NameLength));
entries[i] = entry;
br.ReadBytes(entry.ExtraFieldSize + entry.FileCommentLength);
}
else
{
break;
}
}
}
br.Close();
response.Close();
return entries;
}
}
public struct ZipEntry
{
public short Version;
public short VersionNeeded;
public short Bitflag;
public short CompressionMethod;
public short FileTime;
public short FileDate;
public int CRC32;
public int CompressedSize;
public int UncompressedSize;
public short NameLength;
public short ExtraFieldSize;
public short FileCommentLength;
public short DiskNumberStart;
public short InternalFileAttributes;
public int ExternalFileAttributes;
public int RelativeOffset;
public string Name;
}
</code>Sv: Zip-header eller nåt
- ThomasSv: Zip-header eller nåt
<code>
using System;
using System.Text;
using System.IO;
public class Test
{
public static void Main()
{
ZipEntry[] entries = GetZipEntries("test.zip");
if (entries!=null) {
foreach(ZipEntry entry in entries)
Console.WriteLine(entry.Name + "\t\t" + entry.UncompressedSize);
}
Console.Read();
}
public static ZipEntry[] GetZipEntries(string filename)
{
ZipEntry[] entries = null;
FileStream fs = new FileStream(filename, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
br.BaseStream.Position = br.BaseStream.Length-22;
if (br.ReadInt32() == 0x06054b50)
{
br.BaseStream.Position+=6;
entries = new ZipEntry[br.ReadInt16()];
br.BaseStream.Position+=4;
int offset = br.ReadInt32();
br.BaseStream.Position=offset;
for(int i=0;i<entries.Length;i++)
{
if (br.ReadInt32() == 0x02014b50)
{
ZipEntry entry = new ZipEntry();
entry.Version = br.ReadInt16();
entry.VersionNeeded = br.ReadInt16();
entry.Bitflag = br.ReadInt16();
entry.CompressionMethod = br.ReadInt16();
entry.FileTime = br.ReadInt16();
entry.FileDate = br.ReadInt16();
entry.CRC32 = br.ReadInt32();
entry.CompressedSize = br.ReadInt32();
entry.UncompressedSize = br.ReadInt32();
entry.NameLength = br.ReadInt16();
entry.ExtraFieldSize = br.ReadInt16();
entry.FileCommentLength = br.ReadInt16();
entry.DiskNumberStart = br.ReadInt16();
entry.InternalFileAttributes = br.ReadInt16();
entry.ExternalFileAttributes = br.ReadInt32();
entry.RelativeOffset = br.ReadInt32();
entry.Name = Encoding.UTF8.GetString(br.ReadBytes(entry.NameLength));
entries[i] = entry;
br.ReadBytes(entry.ExtraFieldSize + entry.FileCommentLength);
}
else
{
break;
}
}
}
br.Close();
fs.Close();
return entries;
}
}
public struct ZipEntry
{
public short Version;
public short VersionNeeded;
public short Bitflag;
public short CompressionMethod;
public short FileTime;
public short FileDate;
public int CRC32;
public int CompressedSize;
public int UncompressedSize;
public short NameLength;
public short ExtraFieldSize;
public short FileCommentLength;
public short DiskNumberStart;
public short InternalFileAttributes;
public int ExternalFileAttributes;
public int RelativeOffset;
public string Name;
}
</code>Sv: Zip-header eller nåt
<code>
using System;
using System.Text;
using System.IO;
public class Test
{
public static void Main()
{
ZipEntry[] entries = GetZipEntries("test.zip");
if (entries!=null) {
foreach(ZipEntry entry in entries)
Console.WriteLine(entry.Name + "\t\t" + entry.UncompressedSize);
}
Console.Read();
}
public static ZipEntry[] GetZipEntries(string filename)
{
ZipEntry[] entries = null;
FileStream fs = new FileStream(filename, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
br.BaseStream.Position = br.BaseStream.Length-22;
if (br.ReadInt32() == 0x06054b50)
{
br.BaseStream.Position+=6;
entries = new ZipEntry[br.ReadInt16()];
br.BaseStream.Position+=4;
int offset = br.ReadInt32();
br.BaseStream.Position=offset;
for(int i=0;i<entries.Length;i++)
{
if (br.ReadInt32() == 0x02014b50)
{
ZipEntry entry = new ZipEntry();
entry.Version = br.ReadInt16();
entry.VersionNeeded = br.ReadInt16();
entry.Bitflag = br.ReadInt16();
entry.CompressionMethod = br.ReadInt16();
entry.FileTime = br.ReadInt16();
entry.FileDate = br.ReadInt16();
entry.CRC32 = br.ReadInt32();
entry.CompressedSize = br.ReadInt32();
entry.UncompressedSize = br.ReadInt32();
entry.NameLength = br.ReadInt16();
entry.ExtraFieldSize = br.ReadInt16();
entry.FileCommentLength = br.ReadInt16();
entry.DiskNumberStart = br.ReadInt16();
entry.InternalFileAttributes = br.ReadInt16();
entry.ExternalFileAttributes = br.ReadInt32();
entry.RelativeOffset = br.ReadInt32();
entry.Name = Encoding.UTF8.GetString(br.ReadBytes(entry.NameLength));
entries[i] = entry;
br.BaseStream.Position += entry.ExtraFieldSize + entry.FileCommentLength;
}
else
{
break;
}
}
}
br.Close();
fs.Close();
return entries;
}
}
public struct ZipEntry
{
public short Version;
public short VersionNeeded;
public short Bitflag;
public short CompressionMethod;
public short FileTime;
public short FileDate;
public int CRC32;
public int CompressedSize;
public int UncompressedSize;
public short NameLength;
public short ExtraFieldSize;
public short FileCommentLength;
public short DiskNumberStart;
public short InternalFileAttributes;
public int ExternalFileAttributes;
public int RelativeOffset;
public string Name;
}
</code>
/Johan