Documentation ¶
Overview ¶
Package tlcsv provides adapters to read and write GTFS from CSV format files.
Index ¶
- Variables
- func GetString(ent tt.Entity, key string) (string, error)
- func NewShapeFromShapes(shapes []gtfs.Shape) gtfs.Shape
- func ReadEntities[T any](reader *Reader, efn string) chan T
- func ReadRows(in io.Reader, cb func(Row)) error
- func SetString(ent tt.Entity, key string, value string) error
- func ValidateShapes(shapes []gtfs.Shape) []error
- type Adapter
- type DirAdapter
- func (adapter *DirAdapter) AddFile(filename string, reader io.Reader) error
- func (adapter *DirAdapter) Close() error
- func (adapter *DirAdapter) DirSHA1() (string, error)
- func (adapter *DirAdapter) Exists() bool
- func (adapter *DirAdapter) FileInfos() ([]os.FileInfo, error)
- func (adapter *DirAdapter) Open() error
- func (adapter *DirAdapter) OpenFile(filename string, cb func(io.Reader)) error
- func (adapter *DirAdapter) Path() string
- func (adapter *DirAdapter) ReadRows(filename string, cb func(Row)) error
- func (adapter *DirAdapter) SHA1() (string, error)
- func (adapter *DirAdapter) String() string
- func (adapter *DirAdapter) WriteRows(filename string, rows [][]string) error
- type OverlayAdapter
- func (adapter OverlayAdapter) Close() error
- func (adapter OverlayAdapter) CreateZip(outfile string) error
- func (adapter OverlayAdapter) DirSHA1() (string, error)
- func (adapter OverlayAdapter) Exists() bool
- func (adapter OverlayAdapter) Files() ([]string, error)
- func (adapter OverlayAdapter) Open() error
- func (adapter OverlayAdapter) OpenFile(filename string, cb func(io.Reader)) error
- func (adapter OverlayAdapter) Path() string
- func (adapter OverlayAdapter) ReadRows(filename string, cb func(Row)) error
- func (adapter OverlayAdapter) SHA1() (string, error)
- func (adapter OverlayAdapter) String() string
- type Reader
- func (reader *Reader) Agencies() (out chan gtfs.Agency)
- func (reader *Reader) Areas() (out chan gtfs.Area)
- func (reader *Reader) Attributions() (out chan gtfs.Attribution)
- func (reader *Reader) CalendarDates() (out chan gtfs.CalendarDate)
- func (reader *Reader) Calendars() (out chan gtfs.Calendar)
- func (reader *Reader) ContainsFile(filename string) bool
- func (reader *Reader) FareAttributes() (out chan gtfs.FareAttribute)
- func (reader *Reader) FareLegRules() (out chan gtfs.FareLegRule)
- func (reader *Reader) FareMedia() (out chan gtfs.FareMedia)
- func (reader *Reader) FareProducts() (out chan gtfs.FareProduct)
- func (reader *Reader) FareRules() (out chan gtfs.FareRule)
- func (reader *Reader) FareTransferRules() (out chan gtfs.FareTransferRule)
- func (reader *Reader) FeedInfos() (out chan gtfs.FeedInfo)
- func (reader *Reader) Frequencies() (out chan gtfs.Frequency)
- func (reader *Reader) Levels() (out chan gtfs.Level)
- func (reader *Reader) Pathways() (out chan gtfs.Pathway)
- func (reader *Reader) ReadEntities(c interface{}) error
- func (reader *Reader) RiderCategories() (out chan gtfs.RiderCategory)
- func (reader *Reader) Routes() (out chan gtfs.Route)
- func (reader *Reader) Shapes() chan gtfs.Shape
- func (reader *Reader) StopAreas() (out chan gtfs.StopArea)
- func (reader *Reader) StopTimes() (out chan gtfs.StopTime)
- func (reader *Reader) StopTimesByTripID(tripIDs ...string) chan []gtfs.StopTime
- func (reader *Reader) Stops() (out chan gtfs.Stop)
- func (reader *Reader) String() string
- func (reader *Reader) Transfers() (out chan gtfs.Transfer)
- func (reader *Reader) Translations() (out chan gtfs.Translation)
- func (reader *Reader) Trips() (out chan gtfs.Trip)
- func (reader *Reader) ValidateStructure() []error
- type Row
- type TmpZipAdapter
- type URLAdapter
- type Writer
- func (writer *Writer) AddEntities(ents []tt.Entity) ([]string, error)
- func (writer *Writer) AddEntity(ent tt.Entity) (string, error)
- func (writer *Writer) Create() error
- func (writer *Writer) Delete() error
- func (writer *Writer) NewReader() (adapters.Reader, error)
- func (writer *Writer) String() string
- func (writer *Writer) WriteExtraColumns(val bool)
- type WriterAdapter
- type ZipAdapter
- func (adapter *ZipAdapter) Close() error
- func (adapter *ZipAdapter) DirSHA1() (string, error)
- func (adapter *ZipAdapter) Exists() bool
- func (adapter *ZipAdapter) FileInfos() ([]os.FileInfo, error)
- func (adapter *ZipAdapter) Open() error
- func (adapter *ZipAdapter) OpenFile(filename string, cb func(io.Reader)) error
- func (adapter *ZipAdapter) Path() string
- func (adapter *ZipAdapter) ReadRows(filename string, cb func(Row)) error
- func (adapter *ZipAdapter) SHA1() (string, error)
- func (adapter *ZipAdapter) String() string
- type ZipWriterAdapter
Constants ¶
This section is empty.
Variables ¶
var MapperCache = tags.NewCache(reflectx.NewMapperFunc("csv", tags.ToSnakeCase))
Functions ¶
func NewShapeFromShapes ¶ added in v0.18.0
NewShapeFromShapes takes Shapes with single points and returns a Shape with linestring geometry. Any errors from the input errors, or errors such as duplicate sequences, are added as entity errors.
func ReadEntities ¶ added in v0.11.0
func ValidateShapes ¶ added in v0.18.0
ValidateShapes returns errors for an array of shapes.
Types ¶
type Adapter ¶
type Adapter interface { OpenFile(string, func(io.Reader)) error ReadRows(string, func(Row)) error Open() error Close() error Exists() bool Path() string SHA1() (string, error) DirSHA1() (string, error) String() string }
Adapter provides an interface for working with various kinds of GTFS sources: zip, directory, url.
func NewAdapter ¶ added in v0.10.1
NewAdapter returns a basic adapter for the given URL. Use NewURLAdapter() to provide additional options.
type DirAdapter ¶
type DirAdapter struct {
// contains filtered or unexported fields
}
DirAdapter supports plain directories of CSV files.
func NewDirAdapter ¶
func NewDirAdapter(path string) *DirAdapter
NewDirAdapter returns an initialized DirAdapter.
func (*DirAdapter) AddFile ¶ added in v0.8.5
func (adapter *DirAdapter) AddFile(filename string, reader io.Reader) error
AddFile directly adds a file to this directory. Useful for manual feed operations.
func (*DirAdapter) DirSHA1 ¶
func (adapter *DirAdapter) DirSHA1() (string, error)
DirSHA1 returns the SHA1 of all the .txt files in the main directory, sorted, and concatenated.
func (*DirAdapter) Exists ¶
func (adapter *DirAdapter) Exists() bool
Exists checks if the specified directory exists.
func (*DirAdapter) FileInfos ¶
func (adapter *DirAdapter) FileInfos() ([]os.FileInfo, error)
FileInfos returns a list of os.FileInfo for all top-level .txt files.
func (*DirAdapter) Open ¶
func (adapter *DirAdapter) Open() error
Open the adapter. Return an error if the directory does not exist.
func (*DirAdapter) OpenFile ¶
func (adapter *DirAdapter) OpenFile(filename string, cb func(io.Reader)) error
OpenFile opens a file in the directory. Returns an error if the file cannot be read.
type OverlayAdapter ¶
type OverlayAdapter struct {
// contains filtered or unexported fields
}
OverlayAdapter searches a specified list of directories for the specified file. Used for reducing the complexity of writing tests.
func NewOverlayAdapter ¶
func NewOverlayAdapter(paths ...string) OverlayAdapter
NewOverlayAdapter returns a new OverlayAdapter.
func (OverlayAdapter) Close ¶
func (adapter OverlayAdapter) Close() error
Close implements CSV Adapter.Close.
func (OverlayAdapter) CreateZip ¶ added in v0.8.5
func (adapter OverlayAdapter) CreateZip(outfile string) error
func (OverlayAdapter) DirSHA1 ¶
func (adapter OverlayAdapter) DirSHA1() (string, error)
DirSHA1 returns the SHA1 of all the .txt files in the main directory, sorted, and concatenated.
func (OverlayAdapter) Exists ¶
func (adapter OverlayAdapter) Exists() bool
Exists implements CSV Adapter.Exists.
func (OverlayAdapter) Files ¶ added in v0.8.5
func (adapter OverlayAdapter) Files() ([]string, error)
func (OverlayAdapter) Open ¶
func (adapter OverlayAdapter) Open() error
Open implements CSV Adapter Open.
func (OverlayAdapter) OpenFile ¶
func (adapter OverlayAdapter) OpenFile(filename string, cb func(io.Reader)) error
OpenFile searches paths until it finds the specified file.
func (OverlayAdapter) Path ¶
func (adapter OverlayAdapter) Path() string
Path implements CSV Adapter.Path.
func (OverlayAdapter) ReadRows ¶
func (adapter OverlayAdapter) ReadRows(filename string, cb func(Row)) error
ReadRows implements CSV Adapter ReadRows.
func (OverlayAdapter) SHA1 ¶
func (adapter OverlayAdapter) SHA1() (string, error)
SHA1 is an alias for DirSHA1
func (OverlayAdapter) String ¶ added in v0.11.0
func (adapter OverlayAdapter) String() string
type Reader ¶
type Reader struct {
Adapter
}
Reader reads GTFS entities from CSV files.
func NewReaderFromAdapter ¶ added in v0.10.1
func (*Reader) Attributions ¶ added in v0.10.0
func (reader *Reader) Attributions() (out chan gtfs.Attribution)
func (*Reader) CalendarDates ¶
func (reader *Reader) CalendarDates() (out chan gtfs.CalendarDate)
func (*Reader) ContainsFile ¶
ContainsFile checks if filename is present and contains a readable row.
func (*Reader) FareAttributes ¶
func (reader *Reader) FareAttributes() (out chan gtfs.FareAttribute)
func (*Reader) FareLegRules ¶ added in v0.11.0
func (reader *Reader) FareLegRules() (out chan gtfs.FareLegRule)
func (*Reader) FareProducts ¶ added in v0.11.0
func (reader *Reader) FareProducts() (out chan gtfs.FareProduct)
func (*Reader) FareTransferRules ¶ added in v0.11.0
func (reader *Reader) FareTransferRules() (out chan gtfs.FareTransferRule)
func (*Reader) Frequencies ¶
func (*Reader) ReadEntities ¶
ReadEntities provides a generic interface for reading entities.
func (*Reader) RiderCategories ¶ added in v0.11.0
func (reader *Reader) RiderCategories() (out chan gtfs.RiderCategory)
func (*Reader) StopTimesByTripID ¶
StopTimesByTripID sends StopTimes for selected trips.
func (*Reader) Translations ¶ added in v0.10.0
func (reader *Reader) Translations() (out chan gtfs.Translation)
func (*Reader) ValidateStructure ¶
ValidateStructure returns if all required CSV files are present.
type TmpZipAdapter ¶ added in v0.12.0
type TmpZipAdapter struct { ZipAdapter // contains filtered or unexported fields }
TmpZipAdapter is similar to ZipAdapter, but deletes the file on close.
func NewStoreAdapter ¶ added in v0.18.0
func NewStoreAdapter(storage string, key string, fragment string) (*TmpZipAdapter, error)
NewStoreAdapter is a convenience method for getting a GTFS Zip reader from the store.
func NewTmpZipAdapterFromReader ¶ added in v0.12.0
func NewTmpZipAdapterFromReader(reader io.Reader, fragment string) (*TmpZipAdapter, error)
func (*TmpZipAdapter) Close ¶ added in v0.12.0
func (adapter *TmpZipAdapter) Close() error
func (*TmpZipAdapter) Open ¶ added in v0.12.0
func (adapter *TmpZipAdapter) Open() error
type URLAdapter ¶
type URLAdapter struct { TmpZipAdapter // contains filtered or unexported fields }
URLAdapter downloads a GTFS URL to a temporary file, and removes the file when it is closed.
func NewURLAdapter ¶ added in v0.10.1
func NewURLAdapter(address string, opts ...request.RequestOption) *URLAdapter
func (*URLAdapter) Open ¶
func (adapter *URLAdapter) Open() error
Open the adapter, and download the provided URL to a temporary file.
func (*URLAdapter) String ¶ added in v0.11.0
func (adapter *URLAdapter) String() string
type Writer ¶
type Writer struct { WriterAdapter // contains filtered or unexported fields }
Writer implements a GTFS CSV Writer.
func (*Writer) AddEntities ¶
AddEntities writes entities to the output.
func (*Writer) WriteExtraColumns ¶ added in v0.11.0
type WriterAdapter ¶
WriterAdapter provides a writing interface.
type ZipAdapter ¶
type ZipAdapter struct {
// contains filtered or unexported fields
}
ZipAdapter supports reading from zip archives.
func NewZipAdapter ¶
func NewZipAdapter(path string) *ZipAdapter
NewZipAdapter returns an initialized zip adapter.
func (*ZipAdapter) DirSHA1 ¶
func (adapter *ZipAdapter) DirSHA1() (string, error)
DirSHA1 returns the SHA1 of all the .txt files in the main directory, sorted, and concatenated.
func (*ZipAdapter) Exists ¶
func (adapter *ZipAdapter) Exists() bool
Exists returns if the zip file exists.
func (*ZipAdapter) FileInfos ¶
func (adapter *ZipAdapter) FileInfos() ([]os.FileInfo, error)
FileInfos returns a list of os.FileInfo for all .txt files.
func (*ZipAdapter) Open ¶
func (adapter *ZipAdapter) Open() error
Open the adapter. Return an error if the file does not exist.
func (*ZipAdapter) OpenFile ¶
func (adapter *ZipAdapter) OpenFile(filename string, cb func(io.Reader)) error
OpenFile opens the file inside the archive and passes it to the provided callback.
func (*ZipAdapter) Path ¶
func (adapter *ZipAdapter) Path() string
Path returns the path to the zip file.
func (*ZipAdapter) ReadRows ¶
func (adapter *ZipAdapter) ReadRows(filename string, cb func(Row)) error
ReadRows opens the specified file and runs the callback on each Row. An error is returned if the file cannot be read.
func (*ZipAdapter) SHA1 ¶
func (adapter *ZipAdapter) SHA1() (string, error)
SHA1 returns the SHA1 checksum of the zip archive.
func (*ZipAdapter) String ¶ added in v0.11.0
func (adapter *ZipAdapter) String() string
type ZipWriterAdapter ¶
type ZipWriterAdapter struct { DirAdapter // contains filtered or unexported fields }
ZipWriterAdapter functions the same as DirAdapter, but writes to a temporary directory, and creates a zip archive when closed.
func NewZipWriterAdapter ¶
func NewZipWriterAdapter(path string) *ZipWriterAdapter
NewZipWriterAdapter returns a new ZipWriterAdapter.
func (*ZipWriterAdapter) Close ¶
func (adapter *ZipWriterAdapter) Close() error
Close creates a zip archive of all the written files at the specified destination.