restructure: console→client-console, add admin-console skeleton, move docs to doc/
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
// buildZip создаёт zip-архив с одним файлом fileName и содержимым content.
|
||||
// Вспомогательная функция: используется в buildScriptZip (PHP/Ruby),
|
||||
// а также как основа для buildGoSourceZip и buildJSDeployZip.
|
||||
func buildZip(fileName string, content []byte) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
|
||||
fw, err := zw.Create(fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := fw.Write(content); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := zw.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// buildZipTwo создаёт zip-архив с двумя файлами.
|
||||
// Используется когда пользователь указал файл зависимостей (requirements.txt и т.д.).
|
||||
func buildZipTwo(file1, file2 string, content1, content2 []byte) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
|
||||
for _, f := range []struct {
|
||||
name string
|
||||
content []byte
|
||||
}{{file1, content1}, {file2, content2}} {
|
||||
fw, err := zw.Create(f.name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := fw.Write(f.content); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err := zw.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user