Skip to content

Commit

Permalink
v0.1.1; fix README, rename streaming to make_stream
Browse files Browse the repository at this point in the history
- fix README
Includes examples repo, and fix link

- streaming introduced in v0.1.0 is now make_stream
this is a breaking change, but since it was released less than 24 hours
ago, and spirit is still considered in development, it is meant as a
quick patch release
  • Loading branch information
hnry committed Aug 12, 2016
1 parent 72a2cfb commit 264ca0b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ To install `npm install spirit`

Most likely, you will want to use [spirit-router](https://github.com/spirit-js/spirit-router) as a handler for spirit. (Unless you are interested in writing one yourself, or using another handler).

[spirit API Docs](docs/api)
[spirit + spirit-router Guide](https://github.com/spirit-js/spirit-router/tree/master/docs/Guide.md)
- [collection of Examples](https://github.com/spirit-js/examples)
- [spirit API Docs](docs/api)
- [spirit + spirit-router Guide](https://github.com/spirit-js/spirit-router/tree/master/docs/Guide.md)


## Notable Extensions
###### Adapters
[node-adapter](docs/api/node-adapter.md): Interfaces with node's http, https, and http2 module. It's optionally bundled with spirit.
[node-adapter](https://github.com/spirit-js/spirit/blob/master/docs/api/node.md#adapter): Interfaces with node's http, https, and http2 module. It's optionally bundled with spirit.

###### Middlewares
[spirit-express](https://github.com/spirit-js/spirit-express): A wrapper for Express API & middleware to get them to work as spirit middleware.
Expand Down
12 changes: 7 additions & 5 deletions docs/api/node.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- [adapter](#adapter) node http adapter

- [streaming](#streaming) creates a writable stream (useful for creating a streaming response)
- [make_stream](#make_stream) creates a writable stream (useful for creating a streaming response)

Functions for creating common responses with chainable helpers:
- [response](#response)
Expand Down Expand Up @@ -57,8 +57,10 @@ And a response would flow backwards in the same order:
-------------------------------------------


# streaming
##### (spirit.node.streaming)
# make_stream
##### (spirit.node.make_stream)
##### Added 0.1.1
##### Alias makeStream

It is meant as a helper to create a generic writable stream for when you need to stream a response body.

Expand All @@ -68,7 +70,7 @@ __Note__, if you already have a stream, you do not need to use this function. It

Example:
```js
const res = streaming()
const res = make_stream()

// pass res to some async function, or can do some async here
setTimeout(() => {
Expand All @@ -94,7 +96,7 @@ In the example:

4. another 1000ms later, the final chunk of the response body is written to the client, and the stream has ended, thus ending the response.

[Source: src/http/response.js (streaming)](../../src/http/response.js#L57)
[Source: src/http/response.js (make_stream)](../../src/http/response.js#L57)

#### Arguments
None
Expand Down
8 changes: 4 additions & 4 deletions spec/http/response-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const response = require("../../lib/http/response")
const response = require("../../index").node
const Response = require("../../lib/http/response-class").Response
const fs = require("fs")

Expand Down Expand Up @@ -32,7 +32,7 @@ describe("http.response", () => {
})

const stream = require("stream")
describe("streaming", () => {
describe("make_stream", () => {
it("returns a writable stream", (done) => {
const buf = []
const t = new stream.Transform({
Expand All @@ -43,7 +43,7 @@ describe("http.response", () => {
}
})

const s = response.streaming()
const s = response.make_stream()
s.write("test")
s.write("1")
s.write("2")
Expand All @@ -52,7 +52,7 @@ describe("http.response", () => {
})

it("using with a response is ok", () => {
const s = response.streaming()
const s = response.make_stream()
const resp = response.response(s)
expect(resp.status).toBe(200)
expect(resp.headers).toEqual({})
Expand Down
7 changes: 4 additions & 3 deletions src/http/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require("fs")
const path = require("path")
const Promise = require("bluebird")

const stream = require("stream") // for stream_response
const stream = require("stream") // for make_stream

/**
* checks if `resp` is a valid response map
Expand Down Expand Up @@ -59,7 +59,7 @@ const response = (body) => {
*
* @return {stream.Transform}
*/
const streaming = () => {
const make_stream = () => {
return new stream.Transform({
transform(data, encoding, callback) {
this.push(data)
Expand Down Expand Up @@ -176,7 +176,8 @@ module.exports = {
is_response,
isResponse: is_response, // alias

streaming,
make_stream,
makeStream: make_stream, // alias

response,

Expand Down

0 comments on commit 264ca0b

Please sign in to comment.