From 4d63d4ae43feb083e01942b3485ca2c0fa130b85 Mon Sep 17 00:00:00 2001 From: badkaktus Date: Fri, 11 Oct 2019 15:52:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples.txt | 2 +- .../temporary-files-and-directories.go | 55 +++++++++---------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/examples.txt b/examples.txt index 61f23ee..2364199 100644 --- a/examples.txt +++ b/examples.txt @@ -60,7 +60,7 @@ Epoch Строковые фильтры (Line Filters) Пути к файлам (File Paths) Директории (Directories) -Temporary Files and Directories +Временные файлы и директории (Temporary Files and Directories) Testing Command-Line Arguments Command-Line Flags diff --git a/examples/temporary-files-and-directories/temporary-files-and-directories.go b/examples/temporary-files-and-directories/temporary-files-and-directories.go index abed14e..ae89867 100644 --- a/examples/temporary-files-and-directories/temporary-files-and-directories.go +++ b/examples/temporary-files-and-directories/temporary-files-and-directories.go @@ -1,8 +1,8 @@ -// Throughout program execution, we often want to create -// data that isn't needed after the program exits. -// *Temporary files and directories* are useful for this -// purpose since they don't pollute the file system over -// time. +// Во время выполнения программы мы часто хотим создавать +// данные, которые не нужны после выхода из программы. +// *Временные файлы и каталоги* полезны для этой цели, +// поскольку они не загрязняют файловую систему с +// течением времени. package main @@ -21,44 +21,43 @@ func check(e error) { func main() { - // The easiest way to create a temporary file is by - // calling `ioutil.TempFile`. It creates a file *and* - // opens it for reading and writing. We provide `""` - // as the first argument, so `ioutil.TempFile` will - // create the file in the default location for our OS. + // Простейший способ создания временного файла - это + // вызов `ioutil.TempFile`. Он создаст *и* откроет + // файл для чтения и записи. Мы использовали `""` в + // качестве первого аргумента, и поэтому `ioutil.TempFile` + // создаст файл в директории по-умолчанию. f, err := ioutil.TempFile("", "sample") check(err) - // Display the name of the temporary file. On - // Unix-based OSes the directory will likely be `/tmp`. - // The file name starts with the prefix given as the - // second argument to `ioutil.TempFile` and the rest - // is chosen automatically to ensure that concurrent - // calls will always create different file names. + // Показать имя временного файла. В ОС на основе Unix + // каталог, вероятно, будет `/tmp`. Имя файла начинается + // с префикса, заданного в качестве второго аргумента + // `ioutil.TempFile`, а остальное выбирается автоматически, + // чтобы параллельные вызовы всегда создавали разные + // имена файлов. fmt.Println("Temp file name:", f.Name()) - // Clean up the file after we're done. The OS is - // likely to clean up temporary files by itself after - // some time, but it's good practice to do this - // explicitly. + // Удалите файл после того, как мы закончим. Через + // некоторое время ОС, скорее всего, сама очистит + // временные файлы, но рекомендуется делать это явно. defer os.Remove(f.Name()) - // We can write some data to the file. + // Мы можем записать какую-то информацию в файл. _, err = f.Write([]byte{1, 2, 3, 4}) check(err) - // If we intend to write many temporary files, we may - // prefer to create a temporary *directory*. - // `ioutil.TempDir`'s arguments are the same as - // `TempFile`'s, but it returns a directory *name* - // rather than an open file. + // Если мы намереваемся написать много временных файлов, + // мы можем предпочесть создать *временный каталог*. Аргументы + // `ioutil.TempDir` совпадают с аргументами `TempFile`, + // но он возвращает *имя каталога*, а не открытый файл. dname, err := ioutil.TempDir("", "sampledir") fmt.Println("Temp dir name:", dname) defer os.RemoveAll(dname) - // Now we can synthesize temporary file names by - // prefixing them with our temporary directory. + // Теперь мы можем синтезировать временные имена + // файлов, добавив к ним префикс нашего + // временного каталога. fname := filepath.Join(dname, "file1") err = ioutil.WriteFile(fname, []byte{1, 2}, 0666) check(err)