goloadinglzw

How to apply custom decompression to .z file


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.


Solution

  • 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: Convert byte slice to int slice