I have some Go code below which is has PK zipped string. How to get the contents of each file in this zip string?
Below is an attempt using string manipulation I can get the contents of the first file. Is there another way to get the contents without using string functions?
package main
import (
"fmt"
"strings"
)
func main() {
x := "PK\x03\x04\n\x00\x00\x00\x00\x00\x14OOQ\xddDYc\v\x00\x00\x00\v\x00\x00\x00\t\x00\x00\x00file1.txttextfileonePK\x03\x04\n\x00\x00\x00\x00\x00\x1aOOQq?\xb5]\t\x00\x00\x00\t\x00\x00\x00\t\x00\x00\x00file2.txttextfile2PK\x01\x02?\x00\n\x00\x00\x00\x00\x00\x14OOQ\xddDYc\v\x00\x00\x00\v\x00\x00\x00\t\x00$\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00file1.txt\n\x00 \x00\x00\x00\x00\x00\x01\x00\x18\x00#~\xfb\xa7\x85\xa2\xd6\x01#~\xfb\xa7\x85\xa2\xd6\x01\x00\xa8\xdfE\xe7\x8b\xd6\x01PK\x01\x02?\x00\n\x00\x00\x00\x00\x00\x1aOOQq?\xb5]\t\x00\x00\x00\t\x00\x00\x00\t\x00$\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x002\x00\x00\x00file2.txt\n\x00 \x00\x00\x00\x00\x00\x01\x00\x18\x00u\xa7v\xaf\x85\xa2\xd6\x01u\xa7v\xaf\x85\xa2\xd6\x01\xa8\x9eˏ\x85\xa2\xd6\x01PK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\xb6\x00\x00\x00b\x00\x00\x00\x00\x00"
i := strings.Index(x , "PK")
right := x[i+1:]
i = strings.Index(right , "PK")
left := right[:i]
i = strings.LastIndex(left , ".txt")
file1contents := left[i+4:]
fmt.Println("file1contents : ", file1contents)
}
Output of above file1contents : textfileone