當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


GO Dumper用法及代碼示例

GO語言"encoding/hex"包中"Dumper"函數的用法及代碼示例。

用法:

func Dumper(w io.Writer) io.WriteCloser

Dumper 返回一個WriteCloser,它將所有寫入數據的十六進製轉儲寫入 w。轉儲的格式與命令行上的 `hexdump -C` 的輸出相匹配。

例子:

package main

import (
    "encoding/hex"
    "os"
)

func main() {
    lines := []string{
        "Go is an open source programming language.",
        "\n",
        "We encourage all Go users to subscribe to golang-announce.",
    }

    stdoutDumper := hex.Dumper(os.Stdout)

    defer stdoutDumper.Close()

    for _, line := range lines {
        stdoutDumper.Write([]byte(line))
    }

}

輸出:

00000000  47 6f 20 69 73 20 61 6e  20 6f 70 65 6e 20 73 6f  |Go is an open so|
00000010  75 72 63 65 20 70 72 6f  67 72 61 6d 6d 69 6e 67  |urce programming|
00000020  20 6c 61 6e 67 75 61 67  65 2e 0a 57 65 20 65 6e  | language..We en|
00000030  63 6f 75 72 61 67 65 20  61 6c 6c 20 47 6f 20 75  |courage all Go u|
00000040  73 65 72 73 20 74 6f 20  73 75 62 73 63 72 69 62  |sers to subscrib|
00000050  65 20 74 6f 20 67 6f 6c  61 6e 67 2d 61 6e 6e 6f  |e to golang-anno|
00000060  75 6e 63 65 2e                                    |unce.|

相關用法


注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Dumper。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。