已验证 提交 bb0eb4a4 编写于 作者: xurime's avatar xurime

This closes #1075, reload temporary files into memory on save

上级 49c9ea40
......@@ -196,6 +196,14 @@ func (f *File) writeToZip(zw *zip.Writer) error {
_, err = fi.Write(content.([]byte))
return true
})
f.tempFiles.Range(func(path, content interface{}) bool {
var fi io.Writer
fi, err = zw.Create(path.(string))
if err != nil {
return false
}
_, err = fi.Write(f.readBytes(path.(string)))
return true
})
return err
}
......@@ -62,6 +62,15 @@ func TestWriteTo(t *testing.T) {
_, err := f.WriteTo(bufio.NewWriter(&buf))
assert.Nil(t, err)
}
// Test write with temporary file
{
f, buf := File{tempFiles: sync.Map{}}, bytes.Buffer{}
const maxUint16 = 1<<16 - 1
f.tempFiles.Store("s", "")
f.tempFiles.Store(strings.Repeat("s", maxUint16+1), "")
_, err := f.WriteTo(bufio.NewWriter(&buf))
assert.EqualError(t, err, "zip: FileHeader.Name too long")
}
}
func TestClose(t *testing.T) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册