aboutsummaryrefslogtreecommitdiff
path: root/src/archive
diff options
context:
space:
mode:
authorYury Smolsky <yury@smolsky.by>2018-02-25 16:34:35 +0200
committerGiovanni Bajo <rasky@develer.com>2018-02-26 19:58:48 +0000
commit3b7ad1680fa6b97fff29f0af18795bd5f0f6a95a (patch)
treef1d7abd967153aeeabc135cb2f3f1112f17706dc /src/archive
parentfd5bf0393eb7b3a21b55adf2c0f1e293b24cf308 (diff)
downloadgo-3b7ad1680fa6b97fff29f0af18795bd5f0f6a95a.tar.gz
go-3b7ad1680fa6b97fff29f0af18795bd5f0f6a95a.zip
archive/zip: improve Writer.Create documentation on how to add directories
FileHeader.Name also reflects this fact. Fixes #24018 Change-Id: Id0860a9b23c264ac4c6ddd65ba20e0f1f36e4865 Reviewed-on: https://go-review.googlesource.com/97057 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Diffstat (limited to 'src/archive')
-rw-r--r--src/archive/zip/struct.go3
-rw-r--r--src/archive/zip/writer.go3
2 files changed, 4 insertions, 2 deletions
diff --git a/src/archive/zip/struct.go b/src/archive/zip/struct.go
index f613ebdc34..36b551ec2c 100644
--- a/src/archive/zip/struct.go
+++ b/src/archive/zip/struct.go
@@ -82,7 +82,8 @@ const (
type FileHeader struct {
// Name is the name of the file.
// It must be a relative path, not start with a drive letter (e.g. C:),
- // and must use forward slashes instead of back slashes.
+ // and must use forward slashes instead of back slashes. A trailing slash
+ // indicates that this file is a directory and should have no data.
Name string
// Comment is any arbitrary user-defined string shorter than 64KiB.
diff --git a/src/archive/zip/writer.go b/src/archive/zip/writer.go
index 14a5ee48c1..12675d60a0 100644
--- a/src/archive/zip/writer.go
+++ b/src/archive/zip/writer.go
@@ -209,7 +209,8 @@ func (w *Writer) Close() error {
// The file contents will be compressed using the Deflate method.
// The name must be a relative path: it must not start with a drive
// letter (e.g. C:) or leading slash, and only forward slashes are
-// allowed.
+// allowed. To create a directory instead of a file, add a trailing
+// slash to the name.
// The file's contents must be written to the io.Writer before the next
// call to Create, CreateHeader, or Close.
func (w *Writer) Create(name string) (io.Writer, error) {