Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose errorContextLength on struct XLSXFile #38

Merged
merged 1 commit into from Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions Sources/CoreXLSX/CoreXLSX.swift
Expand Up @@ -21,9 +21,26 @@ public struct XLSXFile {
public let filepath: String
private let archive: Archive
private let decoder: XMLDecoder

/// Buffer size passed to `archive.extract` call
private let bufferSize: UInt32

public init?(filepath: String, bufferSize: UInt32 = 10 * 1024 * 1024) {
/// - Parameters:
/// - filepath: path to the `.xlsx` file to be processed.
/// - bufferSize: ZIP archive buffer size, the default is 10KB. You may
/// need to set a bigger buffer size for bigger files.
/// - errorContextLength: The error context length. The default is `0`.
/// Non-zero length makes an error thrown from
/// the XML parser with line/column location repackaged with a context
/// around that location of specified length. For example, if an error was
/// thrown indicating that there's an unexpected character at line 3, column
/// 15 with `errorContextLength` set to 10, a new error type is rethrown
/// containing 5 characters before column 15 and 5 characters after, all on
/// line 3. Line wrapping should be handled correctly too as the context can
/// span more than a few lines.
public init?(filepath: String,
bufferSize: UInt32 = 10 * 1024 * 1024,
errorContextLength: UInt = 0) {
let archiveURL = URL(fileURLWithPath: filepath)

guard let archive = Archive(url: archiveURL, accessMode: .read) else {
Expand All @@ -34,7 +51,9 @@ public struct XLSXFile {
self.filepath = filepath
self.bufferSize = bufferSize

decoder = XMLDecoder()
let decoder = XMLDecoder()
decoder.errorContextLength = errorContextLength
self.decoder = decoder
}

/// Parse a file within `archive` at `path`. Parsing result is
Expand Down