2024-12-09 12:30:41 -06:00
|
|
|
package defrag
|
|
|
|
|
|
2024-12-09 12:49:56 -06:00
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-09 12:30:41 -06:00
|
|
|
func Blocks(diskMap []byte) ([]byte, error) {
|
2024-12-09 12:49:56 -06:00
|
|
|
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
|
2024-12-09 12:30:41 -06:00
|
|
|
}
|