This commit is contained in:
badkaktus 2019-10-11 13:25:59 +03:00
parent 30ac0047a3
commit 186892989f
3 changed files with 19 additions and 19 deletions

View File

@ -54,7 +54,7 @@ Epoch
Парсинг чисел (Number Parsing)
Парсинг URL (URL Parsing)
Хеш SHA1 (SHA1 Hashes)
Base64 Encoding
Кодирование Base64 (Base64 Encoding)
Reading Files
Writing Files
Line Filters

View File

@ -1,11 +1,11 @@
// Go provides built-in support for [base64
// encoding/decoding](http://en.wikipedia.org/wiki/Base64).
// Go имеет встроенную поддержку [base64
// кодирования и декодирования](http://en.wikipedia.org/wiki/Base64).
package main
// This syntax imports the `encoding/base64` package with
// the `b64` name instead of the default `base64`. It'll
// save us some space below.
// Этот синтаксис импортирует пакет `encoding/base64` с
// с алиасом `b64`, вместо названия по-умолчанию. Это
// сэкономит нам немного места.
import (
b64 "encoding/base64"
"fmt"
@ -13,25 +13,25 @@ import (
func main() {
// Here's the `string` we'll encode/decode.
// `Строка`, которую мы будем кодировать/декодировать.
data := "abc123!?$*&()'-=@~"
// Go supports both standard and URL-compatible
// base64. Here's how to encode using the standard
// encoder. The encoder requires a `[]byte` so we
// convert our `string` to that type.
// Go поддерживает оба стандарта и URL-совместимого
// base64. Кодируем, используя стандартнай кодировщик.
// Кодировщик требует `[]byte` на входе, поэтому
// мы конвертируем нашу `строку`.
sEnc := b64.StdEncoding.EncodeToString([]byte(data))
fmt.Println(sEnc)
// Decoding may return an error, which you can check
// if you don't already know the input to be
// well-formed.
// Декодирование может вернуть ошибку, которую можно
// проверить, если вы не уверены в корректности
// входных данных.
sDec, _ := b64.StdEncoding.DecodeString(sEnc)
fmt.Println(string(sDec))
fmt.Println()
// This encodes/decodes using a URL-compatible base64
// format.
// Это кодирование/декодирование использует
// URL-совместимый base64 формат.
uEnc := b64.URLEncoding.EncodeToString([]byte(data))
fmt.Println(uEnc)
uDec, _ := b64.URLEncoding.DecodeString(uEnc)

View File

@ -1,6 +1,6 @@
# The string encodes to slightly different values with the
# standard and URL base64 encoders (trailing `+` vs `-`)
# but they both decode to the original string as desired.
# Строка кодируется в слегка отличающиеся значения с
# помощью стандартных и URL-совместимые base64 (`+` vs `-`),
# но они оба декодируются в исходную строку по желанию.
$ go run base64-encoding.go
YWJjMTIzIT8kKiYoKSctPUB+
abc123!?$*&()'-=@~