第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

GoLang 拖尾 UTF16LE windows 日志文件

GoLang 拖尾 UTF16LE windows 日志文件

Go
慕蓋茨4494581 2023-01-03 11:21:09
我如何結(jié)合這兩個(gè) golang 腳本來(lái)跟蹤 UTF16LEBOM 的活動(dòng)日志?我正在為游戲(Eve Online)開(kāi)發(fā)日志解析器。游戲中的聊天記錄可以保存,我想用GoLang讀取運(yùn)行日志,并在“準(zhǔn)備去死渣男!”中標(biāo)記關(guān)鍵字“去死”。我發(fā)現(xiàn)了兩個(gè)單獨(dú)工作的例子。將它們結(jié)合起來(lái)是一個(gè)我一直無(wú)法弄清楚的挑戰(zhàn)。這里的第一個(gè)尾巴等效項(xiàng): https ://medium.com/@arunprabhu.1/tailing-a-file-in-golang-72944204f22b第二次閱讀文件,使其清晰易讀并且沒(méi)有多余的字符: https ://github.com/TomOnTime/utfutil/我一直在嘗試用“等效”替換 utfutil 中的代碼,但它似乎缺少幾個(gè)功能。// EDIT Almost working. It doesn't look like utfutil is defering the close.package mainimport (    "bufio"    "fmt"    "io"    "time"        "github.com/TomOnTime/utfutil")func main() {    logfilefile := "C:/Users/user/Documents/EVE/logs/Chatlogs/chat_20220709_022129_1006197774.txt"    file, err := utfutil.OpenFile(logfilefile, utfutil.WINDOWS)    if err != nil {        return    }    defer file.Close()    reader := bufio.NewReader(file)    for {        line, err := reader.ReadString('\n')        if err != nil {            if err == io.EOF {                // without this sleep you would hogg the CPU                time.Sleep(500 * time.Millisecond)                continue            }            break        }        fmt.Printf(string(line))    }}<cut white space>        ---------------------------------------------------------------          Channel ID:      local          Channel Name:    Local          Listener:        Steve          Session started: 2022.07.07 16:18:21        ---------------------------------------------------------------[ 2022.07.07 17:11:44 ] Steve > hello world[ 2022.07.07 17:11:48 ] John > hello world[ 2022.07.07 17:11:51 ] James > hello world[ 2022.07.07 19:36:53 ] Bob > hello world
查看完整描述

1 回答

?
慕無(wú)忌1623718

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊

您可以通過(guò)刪除來(lái)簡(jiǎn)化您的代碼github.com/TomOnTime/utfutil(這是對(duì) 的一個(gè)非常薄的包裝golang.org/x/text/encoding/unicode)。鏈接任務(wù)通常也比嘗試一次完成所有事情更簡(jiǎn)單;在這里,我從這個(gè)答案tailReader中借用(稍作改動(dòng))。

注意:我只是非常快速地測(cè)試了下面的內(nèi)容(并且手頭沒(méi)有“Eve Online”日志文件)。

package main


import (

    "bufio"

    "fmt"

    "io"

    "os"

    "time"


    "golang.org/x/text/encoding/unicode"

)


func main() {

    file, err := newTailReader("./Local_20220707_170827_1006197774.txt")

    if err != nil {

        return

    }

    defer file.Close()


    utf := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)

    reader := bufio.NewReader(utf.NewDecoder().Reader(file))


    for {

        line, err := reader.ReadString('\n')

        if err != nil {

            fmt.Println(err)

            break

        }


        fmt.Printf(string(line))

    }


}


// Code copied from https://stackoverflow.com/a/31122253/11810946

// and modified to output contents of file before beginning to 'tail'

type tailReader struct {

    io.ReadCloser

}


func (t tailReader) Read(b []byte) (int, error) {

    for {

        n, err := t.ReadCloser.Read(b)

        if n > 0 {

            return n, nil

        } else if err != io.EOF {

            return n, err

        }

        time.Sleep(10 * time.Millisecond)

    }

}


func newTailReader(fileName string) (tailReader, error) {

    f, err := os.Open(fileName)

    if err != nil {

        return tailReader{}, err

    }

    return tailReader{f}, nil

}


查看完整回答
反對(duì) 回復(fù) 2023-01-03
  • 1 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)