以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]zip文件流问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=173153)

--  作者:zhutangxin
--  发布时间:2021/11/17 1:38:00
--  [求助]zip文件流问题
老师您好,ZipFile有没有返回值,如何判断文件压缩已经压缩结束?

在写一个打包程序,需要将多个文件夹的文件按原来的目录结构放到zip文件中。写了一个内部函数,一次处理一个文件夹
形式代码如下:

Dim zip As New zipFile
zip.create or zip.open ...

for each fl as string in folder 
zip.addfile(fl, \'路径/fl文件名\')
next 
zip.close()

当需压缩多个文件夹时,需多次调用上述内部函数,如果前一个文件特别多时,会出现“流不支持写入”的报错。如果忽略,报错的文件夹没有把所有的文件压缩进去。
可能的原因是 zip.close 并不是zip已经结束,当下次再用 Dim zip As New zipFile 该压缩文件的时候,它将终止前面正在进行的压缩,从而报"流不支持写入"的错误。
有没有什么解决方法?


调用的目标发生了异常。
   在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   在 Foxtable.UserFunctions.Execute(String Name, Object[] Args)
流不支持写入。
   在 System.IO.FileStream.SetLength(Int64 value)
   在 C1.C1Zip.d.a()
   在 C1.C1Zip.d.c()
   在 System.IO.Stream.Dispose()
   在 C1.C1Zip.C1ZipFile.a(Stream A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipFile.a(String A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName, DateTime dateTime)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName)
   在 Foxtable.ZipFile.AddFile(String Filename, String NewFileName)
   在 UserCode.AUo3pUozjTu0u80v5(Object[] Args)

--  作者:zhutangxin
--  发布时间:2021/11/17 4:00:00
--  
用下述语句,也会出现报错,发现Publish\\faces下的表情文件没有打包全。

Dim st As Date = Date.Today

Dim bakName As String = "Publish"

Dim f As String = ProjectPath + bakName  + CSTR(st).Replace("-","") +".zip"

If FileSys.FileExists(f) Then FileSys.DeleteFile(f)

 

Dim zip As new ZipFile

zip.Create(f)

zip.AddFolder(projectpath & "publish")

zip.Close


---------------------------
版本:2021.5.29.1
---------------------------
代码执行出错,错误信息:

System.NotSupportedException: 流不支持写入。
   在 System.IO.FileStream.SetLength(Int64 value)
   在 C1.C1Zip.d.a()
   在 C1.C1Zip.d.c()
   在 System.IO.Stream.Dispose()
   在 C1.C1Zip.C1ZipFile.a(Stream A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipFile.a(String A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName, DateTime dateTime)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName)
   在 C1.C1Zip.C1ZipEntryCollection.a(String A_0, String A_1, Boolean A_2, Int32 A_3)
   在 C1.C1Zip.C1ZipEntryCollection.a(String A_0, String A_1, Boolean A_2, Int32 A_3)
   在 C1.C1Zip.C1ZipEntryCollection.AddFolder(String path)
   在 UserCode.Test()
---------------------------
确定   
---------------------------

[此贴子已经被作者于2021/11/17 4:01:09编辑过]

--  作者:有点蓝
--  发布时间:2021/11/17 8:58:00
--  
我测试没有问题。应该是其它原因,比如杀毒软件,关闭所有杀毒软件试试。把Foxtable设置为使用管理员身份运行,检查publish目录里是否有隐藏的系统文件
--  作者:kgdce
--  发布时间:2023/3/24 10:58:00
--  
经过测试,压缩的文件多时,会随机出现上述问题,和电脑的Cpu运算速度有关系,在一台笔记本电脑win10系统上用一直没问题,换到一个win7云桌面上用,就会有报错,调用的目标发生异常,流不支持写入。