Skip to content

Commit a69a510

Browse files
committed
Fix length for paths with UTF8 characters
Fixes #51
1 parent 1ff1702 commit a69a510

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Sources/SparseRestore/MBDB.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct MBDBRecord {
7676
let properties_count = buffer.readInteger(endianness: .big, as: UInt8.self)!
7777

7878
/*
79+
print("###")
7980
print("domainlen \(domain_len) domain \(domain)")
8081
print("filenamelen \(filename_len) filename \(filename)")
8182
print("linklen \(link_len) link \(link)")
@@ -122,14 +123,17 @@ struct MBDBRecord {
122123
}
123124
var buffer = ByteBufferAllocator().buffer(capacity: capacity)
124125

125-
buffer.writeInteger(Int16(domain.count), endianness: .big, as: Int16.self)
126-
buffer.writeString(domain)
126+
let domainData = domain.data(using: .utf8)!
127+
buffer.writeInteger(Int16(domainData.count), endianness: .big, as: Int16.self)
128+
buffer.writeData(domainData)
127129

128-
buffer.writeInteger(Int16(filename.count), endianness: .big, as: Int16.self)
129-
buffer.writeString(filename)
130+
let filenameData = filename.data(using: .utf8)!
131+
buffer.writeInteger(Int16(filenameData.count), endianness: .big, as: Int16.self)
132+
buffer.writeData(filenameData)
130133

131-
buffer.writeInteger(Int16(link.count), endianness: .big, as: Int16.self)
132-
buffer.writeString(link)
134+
let linkData = link.data(using: .utf8)!
135+
buffer.writeInteger(Int16(linkData.count), endianness: .big, as: Int16.self)
136+
buffer.writeData(linkData)
133137

134138
buffer.writeInteger(Int16(hash.count), endianness: .big, as: Int16.self)
135139
buffer.writeData(hash)

0 commit comments

Comments
 (0)