Skip to content

Commit

Permalink
example, readme 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Mar 13, 2020
1 parent 6c5fab9 commit 1715bfb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
22 changes: 21 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
'use strict'

// todo
const pump = require('pump')
const ndjson = require('ndjson')
const differentialToFullDataset = require('.')

const toFullDataset = differentialToFullDataset({
ttl: 2 * 60 * 1000, // 2 minutes
})

pump(
process.stdin,
ndjson.parse(),
toFullDataset,
(err) => {
if (err) {
console.error(err)
process.exit(1)
} else {
process.stdout.write(toFullDataset.asFeedMessage())
}
}
)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"files": [
"index.js",
"lib"
"lib",
"example.js"
],
"keywords": [
"public transport",
Expand Down
20 changes: 18 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# gtfs-rt-differential-to-full-dataset

**Transform a [GTFS Realtime](https://developers.google.com/transit/gtfs-realtime/) with [`DIFFERENTIAL` incrementality](https://developers.google.com/transit/gtfs-realtime/reference/#enum-incrementality) feed into a [`FULL_DATASET`](https://developers.google.com/transit/gtfs-realtime/reference/#enum-incrementality) dump.**
**Transform a continuous [GTFS Realtime](https://developers.google.com/transit/gtfs-realtime/) stream of [`DIFFERENTIAL` incrementality](https://developers.google.com/transit/gtfs-realtime/reference/#enum-incrementality) data into a [`FULL_DATASET`](https://developers.google.com/transit/gtfs-realtime/reference/#enum-incrementality) dump.**

*Note:* Right now, this package *does not* obey the [draft `DIFFERENTIAL` spec](https://github.com/google/transit/issues/84) exactly. See below and [#1](https://github.com/derhuerst/gtfs-rt-differential-to-full-dataset/issues/1) for details.

[![npm version](https://img.shields.io/npm/v/gtfs-rt-differential-to-full-dataset.svg)](https://www.npmjs.com/package/gtfs-rt-differential-to-full-dataset)
[![build status](https://img.shields.io/travis/derhuerst/gtfs-rt-differential-to-full-dataset.svg)](https://travis-ci.org/derhuerst/gtfs-rt-differential-to-full-dataset)
Expand All @@ -19,9 +21,23 @@ npm install gtfs-rt-differential-to-full-dataset
## Usage

```js
// todo
const toFullDataset = require('gtfs-rt-differential-to-full-dataset')

const toFull = toFullDataset({
ttl: 2 * 60 * 1000, // 2 minutes
})
toFull.on('error')

differentialFeedEntities.pipe(toFull)
setInterval(() => {
console.log(toFull.asFeedMessage())
}, 5000)
```

`toFull` will be a [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable) in [object mode](https://nodejs.org/api/stream.html#stream_object_mode) that expects JS objects in the [`FeedEntity`](https://developers.google.com/transit/gtfs-realtime/reference/#message-feedentity) structure/format.

`toFull.asFeedMessage()` returns a [protocol-buffer-encoded](https://developers.google.com/protocol-buffers/docs/overview) [`FeedMessage`](https://developers.google.com/transit/gtfs-realtime/reference/#message-feedmessage) with all relevant `FeedEntity` that have been written into `toFull` so far.


## Contributing

Expand Down

0 comments on commit 1715bfb

Please sign in to comment.