英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论