package defrag import ( "bytes" "strconv" "strings" ) func Blocks(diskMap []byte) ([]byte, error) { current := 0 onFile := false buff := bytes.Buffer{} for _, by := range diskMap { count, err := strconv.Atoi(string(by)) if err != nil { return nil, err } onFile = !onFile if count == 0 { continue } append := "." if onFile { append = strconv.Itoa(current) current++ } buff.WriteString(strings.Repeat(append, count)) } return buff.Bytes(), nil }