func()

in code/go/internal/spectypes/filesize.go [92:116]


func (s *FileSize) unmarshalString(text string) error {
	match := bytesPattern.FindStringSubmatch(text)
	if len(match) < 3 {
		return fmt.Errorf("invalid format for file size (%s)", text)
	}

	q, err := parseFileSizeInt(match[1])
	if err != nil {
		return fmt.Errorf("invalid format for file size (%s): %w", text, err)
	}

	unit := match[2]
	switch unit {
	case megaByteString:
		*s = FileSize(q) * MegaByte
	case kiloByteString:
		*s = FileSize(q) * KiloByte
	case byteString, "":
		*s = FileSize(q) * Byte
	default:
		return fmt.Errorf("invalid unit for filesize (%s): %s", text, unit)
	}

	return nil
}