Skip to content

Commit 62ac311

Browse files
committed
Fixes
1 parent 2633418 commit 62ac311

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

Sources/FoundationEssentials/Data/Data+Base64.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,14 @@ extension Base64 {
341341
return self.encodeToData(bytes: Array(bytes), options: options)
342342
}
343343

344-
@usableFromInline
345344
static func _encode(input: UnsafeBufferPointer<UInt8>, buffer: UnsafeMutableBufferPointer<UInt8>, length: inout Int, options: Data.Base64EncodingOptions) {
346345
if options.contains(.lineLength64Characters) || options.contains(.lineLength76Characters) {
347346
return self._encodeWithLineBreaks(input: input, buffer: buffer, length: &length, options: options)
348347
}
349348

350349
let omitPaddingCharacter = false // options.contains(.omitPaddingCharacter)
351350

352-
Self.withUnsafeEncodingTablesAsBufferPointers(options: options) { e0, e1 in
351+
Self.withUnsafeEncodingTablesAsBufferPointers(options: options) { (e0, e1) throws(Never) -> Void in
353352
let to = input.count / 3 * 3
354353
var outIndex = 0
355354
for index in stride(from: 0, to: to, by: 3) {
@@ -372,18 +371,19 @@ extension Base64 {
372371

373372
buffer[outIndex] = e0[Int(i1)]
374373

375-
if let i2 = i2, let i3 = i3 {
376-
buffer[outIndex &+ 1] = e1[Int(((i1 & 0x03) &<< 4) | ((i2 &>> 4) & 0x0F))]
377-
buffer[outIndex &+ 2] = e1[Int(((i2 & 0x0F) &<< 2) | ((i3 &>> 6) & 0x03))]
378-
buffer[outIndex &+ 3] = e1[Int(i3)]
379-
outIndex += 4
380-
} else if let i2 = i2 {
374+
if let i2 = i2 {
381375
buffer[outIndex &+ 1] = e1[Int(((i1 & 0x03) &<< 4) | ((i2 &>> 4) & 0x0F))]
382-
buffer[outIndex &+ 2] = e1[Int((i2 & 0x0F) &<< 2)]
383-
outIndex += 3
384-
if !omitPaddingCharacter {
385-
buffer[outIndex] = Self.encodePaddingCharacter
386-
outIndex &+= 1
376+
if let i3 = i3 {
377+
buffer[outIndex &+ 2] = e1[Int(((i2 & 0x0F) &<< 2) | ((i3 &>> 6) & 0x03))]
378+
buffer[outIndex &+ 3] = e1[Int(i3)]
379+
outIndex += 4
380+
} else {
381+
buffer[outIndex &+ 2] = e1[Int((i2 & 0x0F) &<< 2)]
382+
outIndex += 3
383+
if !omitPaddingCharacter {
384+
buffer[outIndex] = Self.encodePaddingCharacter
385+
outIndex &+= 1
386+
}
387387
}
388388
} else {
389389
buffer[outIndex &+ 1] = e1[Int((i1 & 0x03) << 4)]
@@ -522,15 +522,15 @@ extension Base64 {
522522
return capacityWithoutBreaks + lineBreakCapacity
523523
}
524524

525-
static func withUnsafeEncodingTablesAsBufferPointers<R>(options: Data.Base64EncodingOptions, _ body: (UnsafeBufferPointer<UInt8>, UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R {
525+
static func withUnsafeEncodingTablesAsBufferPointers<R, E: Error>(options: Data.Base64EncodingOptions, _ body: (UnsafeBufferPointer<UInt8>, UnsafeBufferPointer<UInt8>) throws(E) -> R) throws(E) -> R {
526526
let encoding0 = Self.encoding0
527527
let encoding1 = Self.encoding1
528528

529529
assert(encoding0.count == 256)
530530
assert(encoding1.count == 256)
531531

532-
return try encoding0.withUnsafeBufferPointer { e0 -> R in
533-
try encoding1.withUnsafeBufferPointer { e1 -> R in
532+
return try encoding0.withUnsafeBufferPointer { e0 throws(E) -> R in
533+
try encoding1.withUnsafeBufferPointer { e1 throws(E) -> R in
534534
try body(e0, e1)
535535
}
536536
}

0 commit comments

Comments
 (0)