All Projects → brutella → swift-csv

brutella / swift-csv

Licence: MIT license
Fast and memory-efficient CSV library in Swift.

Programming Languages

swift
15916 projects
objective c
16641 projects - #2 most used programming language

Labels

Projects that are alternatives of or similar to swift-csv

csvy
Import and Export CSV Data With a YAML Metadata Header
Stars: ✭ 52 (-28.77%)
Mutual labels:  csv
CSV2RDF
Streaming, transforming, SPARQL-based CSV to RDF converter. Apache license.
Stars: ✭ 48 (-34.25%)
Mutual labels:  csv
awesome-csv
Awesome Comma-Separated Values (CSV) - What's Next? - Frequently Asked Questions (F.A.Q.s) - Libraries & Tools
Stars: ✭ 46 (-36.99%)
Mutual labels:  csv
opendata
Open data of Cofacts collaborative fact-checking database
Stars: ✭ 35 (-52.05%)
Mutual labels:  csv
JsObjExporter
A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript Object or DOM element only from the frontend!
Stars: ✭ 58 (-20.55%)
Mutual labels:  csv
Hyde
Call of Duty XAsset compiler that transforms raw assets into digestible data.
Stars: ✭ 15 (-79.45%)
Mutual labels:  csv
gems
Ruby Football Week 2021, June 11th to June 17th - 7 Days of Ruby (Sports) Gems ++ Best of Ruby Gems Series
Stars: ✭ 76 (+4.11%)
Mutual labels:  csv
RecordParser
Zero Allocation Writer/Reader Parser for .NET Core
Stars: ✭ 155 (+112.33%)
Mutual labels:  csv
simple-search-service
A faceted search engine and content API.
Stars: ✭ 38 (-47.95%)
Mutual labels:  csv
midi degradation toolkit
A toolkit for generating datasets of midi files which have been degraded to be 'un-musical'.
Stars: ✭ 29 (-60.27%)
Mutual labels:  csv
georef-ar-api
API del Servicio de Normalización de Datos Geográficos de Argentina.
Stars: ✭ 102 (+39.73%)
Mutual labels:  csv
sheet2dict
Simple XLSX and CSV to dictionary converter
Stars: ✭ 206 (+182.19%)
Mutual labels:  csv
CSV
CSV - AutoHotkey library for working with CSV Files
Stars: ✭ 34 (-53.42%)
Mutual labels:  csv
ok-file-formats
Decoders for PNG, JPEG, WAV, and a few other file formats
Stars: ✭ 72 (-1.37%)
Mutual labels:  csv
transferdb
TransferDB 支持异构数据库 schema 转换、全量数据导出导入以及增量数据同步功能( Oracle 数据库 -> MySQL/TiDB 数据库)
Stars: ✭ 30 (-58.9%)
Mutual labels:  csv
cq
Clojure Command-line Data Processor for JSON, YAML, EDN, XML and more
Stars: ✭ 111 (+52.05%)
Mutual labels:  csv
csv2xls
Put together some CSV files into a single Excel file, in different sheets.
Stars: ✭ 14 (-80.82%)
Mutual labels:  csv
datapackage-go
A Go library for working with Data Package.
Stars: ✭ 22 (-69.86%)
Mutual labels:  csv
odin
Data-structure definition/validation/traversal, mapping and serialisation toolkit for Python
Stars: ✭ 24 (-67.12%)
Mutual labels:  csv
idataapi-transform
Full async support toolkit for IDataAPI for efficiency work, read data from API/ES/csv/xlsx/json/redis/mysql/mongo/kafka, write to ES/csv/xlsx/json/redis/mysql/mongo/kafka, provide CLI and python API
Stars: ✭ 36 (-50.68%)
Mutual labels:  csv

swift-csv

swift-csv is a stream based CSV library written in Swift. It uses InputStream to parse a CSV file and OutputStream to write CSV data to a file. This way it doesn't keep everything in memory while working with big CSV files. It also supports BOM for UTF-8, UTF-16 and UTF-32 text encodings.

swift-csv is battle tested in the CSV import and export of Finances.

Features

  • Stream based CSV parser and writer
  • Complete documentation
  • Unit tested

Usage

Parser

let stream = InputStream(...)

// Define the delimeter and encoding of the CSV file
let configuration = CSV.Configuration(delimiter: ",", encoding: .utf8)

let parser = CSV.Parser(inputStream: stream, configuration: configuration)
try parser.parse()

If you don't know the delimiter and encoding of the data, you can automatically detect it.

let url = ...
guard let configuration = CSV.Configuration.detectConfigurationForContentsOfURL(url) else {
	return
}

Example

Parsing this CSV file

a,b
1,"ha ""ha"" ha"
3,4

will result in the following delegate calls.

parserDidBeginDocument
parser(_:didBeginLineAt:) 0
parser(_:didReadFieldAt:value:) a
parser(_:didReadFieldAt:value:) b
parser(_:didEndLineAt:) 0
parser(_:didBeginLineAt:) 1
parser(_:didReadFieldAt:value:) 1
parser(_:didReadFieldAt:value:) ha "ha" ha
parser(_:didEndLineAt:) 1
parser(_:didBeginLineAt:) 2
parser(_:didReadFieldAt:value:) 3
parser(_:didReadFieldAt:value:) 4
parser(_:didEndLineAt:) 2
parserDidEndDocument

Writer

let stream = OutputStream(...)
let configuration = CSV.Configuration(delimiter: ",", encoding: .utf8)

let writer = CSV.Writer(outputStream: stream, configuration: configuration)
try writer.writeLine(of: ["a", "b", "c"])
try writer.writeLine(of: ["1", "2", "3"])

The code above produces the following output.

a,b,c
1,2,3

TODOs

  • Support comments in CSV file

Contact

Matthias Hochgatterer

Github: https://github.com/brutella/

Twitter: https://twitter.com/brutella

License

swift-csv is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].