Compare commits
7
Commits
d27eb91952
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82085eaaf9 | ||
|
|
493b7dd9d4 | ||
|
|
723f046ea4 | ||
|
|
bb970e4f42 | ||
|
|
1b20188dfc | ||
|
|
886f991ee3 | ||
|
|
659b817252 |
@@ -14,5 +14,8 @@ General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
## Important Note
|
## Executive Summary
|
||||||
This library is not yet ready for release. As such, all code should be considered to be unstable and subject to change at any time.
|
This library allows for reading and writing to and from CSV files in a streaming manner. Files can be read and written to on a row-by-row basis allowing larger files to be worked with, since the whole file doesn't have to be loaded to manipulate it. It is based on the [conduit](https://hackage.haskell.org/package/conduit] library.
|
||||||
|
|
||||||
|
## Pull Requests
|
||||||
|
Please make pull requests to the `dev` branch.
|
||||||
|
|||||||
+3
-1
@@ -5,10 +5,12 @@ cabal-version: 2.2
|
|||||||
-- see: https://github.com/sol/hpack
|
-- see: https://github.com/sol/hpack
|
||||||
|
|
||||||
name: csv-sip
|
name: csv-sip
|
||||||
version: 0.0.0
|
version: 0.1.0
|
||||||
synopsis: extracts data from a CSV file
|
synopsis: extracts data from a CSV file
|
||||||
description: extracts data from a CSV file - see README.md for more details
|
description: extracts data from a CSV file - see README.md for more details
|
||||||
category: Data
|
category: Data
|
||||||
|
homepage: https://codeberg.org/jlamothe/csv-sip
|
||||||
|
bug-reports: https://codeberg.org/jlamothe/csv-sip/issues
|
||||||
author: Jonathan Lamothe
|
author: Jonathan Lamothe
|
||||||
maintainer: jonathan@jlamothe.net
|
maintainer: jonathan@jlamothe.net
|
||||||
copyright: (C) 2022 Jonathan Lamothe
|
copyright: (C) 2022 Jonathan Lamothe
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,5 @@
|
|||||||
name: csv-sip
|
name: csv-sip
|
||||||
version: 0.0.0
|
version: 0.1.0
|
||||||
license: GPL-3.0-or-later
|
license: GPL-3.0-or-later
|
||||||
author: "Jonathan Lamothe"
|
author: "Jonathan Lamothe"
|
||||||
maintainer: "jonathan@jlamothe.net"
|
maintainer: "jonathan@jlamothe.net"
|
||||||
@@ -17,6 +17,8 @@ category: Data
|
|||||||
# complications of embedding Haddock markup inside cabal files, it is
|
# complications of embedding Haddock markup inside cabal files, it is
|
||||||
# common to point users to the README.md file.
|
# common to point users to the README.md file.
|
||||||
description: extracts data from a CSV file - see README.md for more details
|
description: extracts data from a CSV file - see README.md for more details
|
||||||
|
homepage: https://codeberg.org/jlamothe/csv-sip
|
||||||
|
bug-reports: https://codeberg.org/jlamothe/csv-sip/issues
|
||||||
|
|
||||||
ghc-options:
|
ghc-options:
|
||||||
- -Wall
|
- -Wall
|
||||||
|
|||||||
+35
-20
@@ -35,15 +35,20 @@ module Data.CSV.Sip (
|
|||||||
-- ** Write an entire CSV file
|
-- ** Write an entire CSV file
|
||||||
writeCSV,
|
writeCSV,
|
||||||
writeRawCSV,
|
writeRawCSV,
|
||||||
writeCSVFromStream,
|
|
||||||
writeRawCSVFromStream,
|
|
||||||
-- * Conduits
|
-- * Conduits
|
||||||
-- ** Encoding
|
-- ** Producers
|
||||||
|
readFromCSV,
|
||||||
|
readFromCSVRaw,
|
||||||
encodeCSV,
|
encodeCSV,
|
||||||
encodeRawCSV,
|
encodeRawCSV,
|
||||||
|
-- ** Consumers
|
||||||
|
writeToCSV,
|
||||||
|
writeToCSVRaw,
|
||||||
|
-- ** Transformers
|
||||||
|
-- *** Encoding
|
||||||
encodeRows,
|
encodeRows,
|
||||||
encodeRawRows,
|
encodeRawRows,
|
||||||
-- ** Decoding
|
-- *** Decoding
|
||||||
labelFields,
|
labelFields,
|
||||||
decodeRows,
|
decodeRows,
|
||||||
decodeRawRows,
|
decodeRawRows,
|
||||||
@@ -127,27 +132,21 @@ writeRawCSV
|
|||||||
-> m ()
|
-> m ()
|
||||||
writeRawCSV file csv = runConduit $ encodeRawCSV csv .| sinkFile file
|
writeRawCSV file csv = runConduit $ encodeRawCSV csv .| sinkFile file
|
||||||
|
|
||||||
-- | Write a CSV file from a stream of Text-based rows
|
-- | reads a stream of Text-based rows from a CSV file
|
||||||
writeCSVFromStream
|
readFromCSV
|
||||||
:: MonadResource m
|
:: MonadResource m
|
||||||
=> FilePath
|
=> FilePath
|
||||||
-- ^ the path to the file to write to
|
-- ^ the path to the CSV file to read from
|
||||||
-> ConduitT () [T.Text] m ()
|
-> ConduitT i [T.Text] m ()
|
||||||
-- ^ the source conduit
|
readFromCSV file = sourceFile file .| decodeRows
|
||||||
-> m ()
|
|
||||||
writeCSVFromStream file src = runConduit $
|
|
||||||
src .| encodeRows .| sinkFile file
|
|
||||||
|
|
||||||
-- | Write a CSV file from a stream of ByteString-based rows
|
-- | reads a stream of ByteString-based rows from a CSV file
|
||||||
writeRawCSVFromStream
|
readFromCSVRaw
|
||||||
:: MonadResource m
|
:: MonadResource m
|
||||||
=> FilePath
|
=> FilePath
|
||||||
-- ^ the path to the file to write to
|
-- ^ the path to the CSV file to read from
|
||||||
-> ConduitT () [BS.ByteString] m ()
|
-> ConduitT i [BS.ByteString] m ()
|
||||||
-- ^ the source conduit
|
readFromCSVRaw file = sourceFile file .| decodeRawRows
|
||||||
-> m ()
|
|
||||||
writeRawCSVFromStream file src = runConduit $
|
|
||||||
src .| encodeRawRows .| sinkFile file
|
|
||||||
|
|
||||||
-- | encode an entire CSV file
|
-- | encode an entire CSV file
|
||||||
encodeCSV
|
encodeCSV
|
||||||
@@ -165,6 +164,22 @@ encodeRawCSV
|
|||||||
-> ConduitT () BS.ByteString m ()
|
-> ConduitT () BS.ByteString m ()
|
||||||
encodeRawCSV csv = sourceList csv .| encodeRawRows
|
encodeRawCSV csv = sourceList csv .| encodeRawRows
|
||||||
|
|
||||||
|
-- | Writes a stream of Text-based rows to a CSV file
|
||||||
|
writeToCSV
|
||||||
|
:: MonadResource m
|
||||||
|
=> FilePath
|
||||||
|
-- ^ the path to the CSV file to write to
|
||||||
|
-> ConduitT [T.Text] o m ()
|
||||||
|
writeToCSV file = encodeRows .| sinkFile file
|
||||||
|
|
||||||
|
-- | Writes a stream of ByteString-based rows to a CSV file
|
||||||
|
writeToCSVRaw
|
||||||
|
:: MonadResource m
|
||||||
|
=> FilePath
|
||||||
|
-- ^ the path to the CSV file to write to
|
||||||
|
-> ConduitT [BS.ByteString] o m ()
|
||||||
|
writeToCSVRaw file = encodeRawRows .| sinkFile file
|
||||||
|
|
||||||
-- | encode a CSV stream row by row, each element in the list read
|
-- | encode a CSV stream row by row, each element in the list read
|
||||||
-- represents a field, with the entire list representing a row
|
-- represents a field, with the entire list representing a row
|
||||||
encodeRows :: Monad m => ConduitT [T.Text] BS.ByteString m ()
|
encodeRows :: Monad m => ConduitT [T.Text] BS.ByteString m ()
|
||||||
|
|||||||
Reference in New Issue
Block a user