Skip to content

Commit

Permalink
two da
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Dec 17, 2024
1 parent b5a294d commit 79d30fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Blockchain/Sources/Blockchain/DataStore/DataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ public final class DataStore: Sendable {
}

// partitioning files so that we won't have too many files in a single directory
private func path(for name: String) -> URL {
var path = basePath
private func getPath(path: String, name: String) -> URL {
var ret = basePath
ret.append(component: path)
var name = name[...]
if let first = name.first {
path = path.appendingPathComponent(String(first), isDirectory: true)
ret.append(component: String(first), directoryHint: .isDirectory)
name = name.dropFirst()
}
if let second = name.first {
path = path.appendingPathComponent(String(second), isDirectory: true)
ret.append(component: String(second), directoryHint: .isDirectory)
name = name.dropFirst()
}
return path.appendingPathComponent(String(name), isDirectory: false)
ret.append(component: String(name), directoryHint: .notDirectory)
return ret
}

public func read(name: String) async throws -> Data? {
try await impl.read(path: path(for: name))
public func read(path: String, name: String) async throws -> Data? {
try await impl.read(path: getPath(path: path, name: name))
}

public func write(name: String, value: Data) async throws {
try await impl.write(path: path(for: name), value: value)
public func write(path: String, name: String, value: Data) async throws {
try await impl.write(path: getPath(path: path, name: name), value: value)
}

public func delete(name: String) async throws {
try await impl.delete(path: path(for: name))
public func delete(path: String, name: String) async throws {
try await impl.delete(path: getPath(path: path, name: name))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import Foundation
import TracingUtils
import Utils

enum DataAvailabilityStore: String, Sendable {
case imports
case audits
}

public final class DataAvailability: ServiceBase2, @unchecked Sendable {
private let dataProvider: BlockchainDataProvider
private let dataStore: DataStore
Expand Down

0 comments on commit 79d30fb

Please sign in to comment.