|
- // 定义文件解压函数
- UnZipFiles = (ZIPFile) =>
- let
- Header = BinaryFormat.Record([
- MiscHeader = BinaryFormat.Binary(14),
- BinarySize = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
- FileSize = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
- FileNameLen= BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian),
- ExtrasLen = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian)
- ]),
-
- HeaderChoice = BinaryFormat.Choice(
- BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
- each if _ <> 67324752 // not the IsValid number? then return a dummy formatter
- then BinaryFormat.Record([IsValid = false, Filename=null, Content=null])
- else BinaryFormat.Choice(
- BinaryFormat.Binary(26), // Header payload - 14+4+4+2+2
- each BinaryFormat.Record([
- IsValid = true,
- Filename = BinaryFormat.Text(Header(_)[FileNameLen]),
- Extras = BinaryFormat.Text(Header(_)[ExtrasLen]),
- Content = BinaryFormat.Transform(
- BinaryFormat.Binary(Header(_)[BinarySize]),
- (x) => try Binary.Buffer(Binary.Decompress(x, Compression.Deflate)) otherwise null
- )
- ]),
- type binary // enable streaming
- )
- ),
-
- ZipFormat = BinaryFormat.List(HeaderChoice, each _[IsValid] = true),
-
- Entries = List.Transform(
- List.RemoveLastN( ZipFormat(ZIPFile), 1),
- (e) => [FileName = e[Filename], Content = e[Content] ]
- )
- in
- Table.FromRecords(Entries)
- // 调用文件解压函数
- let
- 源 = File.Contents("C:\Users\Administrator\Desktop\ZipFile\新建文件夹.zip"),
- Resulte = UnZipFiles(源)
- in
- Resulte
复制代码
|
|