如何对.z文件应用自定义解压缩方法

huangapple go评论69阅读模式
英文:

How to apply custom decompression to .z file

问题

我已经用Go语言编写了一个LZW解码算法,作为工作申请的一部分。LZW编码是一系列整数,可以解码为字符串。我基本上写了一个类似下面这样的函数:

func LZWdecoder(code []int) string {
    // *执行解码操作*
    return decodedString
}

他们给了我一个以.z结尾的文件,该文件使用LZW编码进行了编码,所以我可以在上面测试我的算法(解码为可读的文本)。

然而,我不知道如何将该文件"加载"到一个整数切片中,以便我可以通过我的函数运行它。非常感谢您的帮助。

英文:

I have written a LZW decoder algorithm in Go for a programming task required as part of a job application. A LZW code is a sequence of integers which can be decoded as a string. I have basically written a function that looks like this:

func LZWdecoder(code []int) string {
	// * perform decoding *
	return decodedString
}

They have provided me with a .z file which is encoded using LZW encoding so I can test my algorithm on it (it decodes to human readable text).

However, I don't know how to "load" that file into an integer slice that I can run through my function. Any help would be greatly appreciated.

答案1

得分: 1

使用import os然后os.ReadFile("filename.z")应该返回一个字节切片,然后你可以使用这里描述的方法将其转换为整数切片:https://stackoverflow.com/questions/48178008/convert-byte-slice-to-int-slice

英文:

Use import os then os.ReadFile("filename.z") should return a slice of bytes, which you can then convert to a slice of int using the method described here: https://stackoverflow.com/questions/48178008/convert-byte-slice-to-int-slice

huangapple
  • 本文由 发表于 2022年10月24日 06:57:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/74175369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定