Skip to content

Commit 93a1f0c

Browse files
authored
Merge pull request #16 from brampf/14-incorrect-endianness
Fixing issue #14
2 parents a750b17 + 85aed89 commit 93a1f0c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/FITS/HDU/AnyImageHDU.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ open class AnyImageHDU : AnyHDU {
4242

4343
var new = Data()
4444
vectors.forEach { vector in
45-
let data = vector.withUnsafeBytes { ptr in
45+
// and don't foret the bigEndian here or data is screwed (Fixing issue #14)
46+
let data = vector.bigEndian.withUnsafeBytes { ptr in
4647
Data(buffer: ptr.bindMemory(to: ByteFormat.self))
4748
}
4849
new.append(data)
@@ -63,7 +64,8 @@ open class AnyImageHDU : AnyHDU {
6364

6465
var new = Data()
6566
vectors.forEach { vector in
66-
let data = vector.withUnsafeBytes { ptr in
67+
// and don't foret the bigEndian here or data is screwed (Fixing issue #14)
68+
let data = vector.bigEndian.withUnsafeBytes { ptr in
6769
Data(buffer: ptr.bindMemory(to: ByteFormat.self))
6870
}
6971
new.append(data)
@@ -103,12 +105,14 @@ open class AnyImageHDU : AnyHDU {
103105

104106
if var data = self.dataUnit as? Data {
105107
// append to data unit
106-
vector.withUnsafeBytes { ptr in
108+
// and don't foret the bigEndian here or data is screwed (Fixing issue #14)
109+
vector.bigEndian.withUnsafeBytes { ptr in
107110
data.append(ptr.bindMemory(to: ByteFormat.self))
108111
}
109112
} else {
110113
// set data unit
111-
self.dataUnit = vector.withUnsafeBytes{ ptr in
114+
// and don't foret the bigEndian here or data is screwed (Fixing issue #14)
115+
self.dataUnit = vector.bigEndian.withUnsafeBytes{ ptr in
112116
Data(buffer: ptr.bindMemory(to: ByteFormat.self))
113117
}
114118

0 commit comments

Comments
 (0)