Skip to content

Commit

Permalink
Merge pull request #220 from observerly/feature/header/AddLineFeedCha…
Browse files Browse the repository at this point in the history
…racteToHeaderRow
  • Loading branch information
michealroberts authored Oct 10, 2024
2 parents 184781f + 28958d5 commit ed82155
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/fits/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,28 @@ func compileFITSHeaderRegEx() *regexp.Regexp {

return regexp.MustCompile(lineRe)
}

// This function adds a line feed character to the end of each 80-byte chunk in the data array.
func (h *FITSHeader) AddLineFeedCharacteToHeaderRow(data []byte, lineEnding string) []byte {
// Create a new buffer:
b := new(bytes.Buffer)

lineEndingAsBytes := []byte(lineEnding)

// Iterate over the byte array in chunks of 80 bytes
for i := 0; i < len(data); i += 80 {
// Calculate the end index for slicing
end := i + 80
if end > len(data) {
end = len(data)
}

// Write the chunk of 80 bytes (or less for the last chunk) to the buffer:
b.Write(data[i:end])

// Add a line feed (LF) after each 80-byte chunk:
b.Write(lineEndingAsBytes)
}

return b.Bytes()
}

0 comments on commit ed82155

Please sign in to comment.