Skip to content

Commit

Permalink
Removed sections that have been sublimed into PR #343
Browse files Browse the repository at this point in the history
  • Loading branch information
tyoshino committed Apr 30, 2015
1 parent 1a49b5e commit 17a7f60
Showing 1 changed file with 19 additions and 89 deletions.
108 changes: 19 additions & 89 deletions BinaryExtension.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Readable Byte Stream
# Readable Byte Stream Semantics Explainer

## Semantics
See PR https://github.com/whatwg/streams/pull/343 for normative definition of semantics in the form of algorithm.

## ReadableByteStream

`ReadableByteStream` has a hidden state. The state can be one of the following:
- `"readable"`: Data may be readable
Expand All @@ -9,55 +11,21 @@

The state is not exposed but is observable by calling the methods on the stream or reader.

## Class ReadableByteStream

### Class Definition

```
class ReadableByteStream {
constructor(underlyingByteSource = {})
cancel(reason)
getReader()
getByobReader()
pipeThrough({ writable, readable }, options)
pipeTo(dest, { preventClose, preventAbort, preventCancel } = {})
}
```

### Properties of the ReadableByteStream Prototype

#### getReader()
### getReader()

The `getReader` method creates a readable stream reader and locks the byte stream to the new reader.

The reader's `read()` method returns a Uint8Array.

#### getByobReader()
### getByobReader()

See [#294](https://github.com/whatwg/streams/issues/294) about method naming.

The `getByobReader` method creates a byob byte stream reader and locks the byte stream to the new reader.

## Class ReadableByteStreamReader
## ReadableByteStreamReader

### Class Definition

```
class ReadableByteStreamReader {
constructor(byteStream)
get closed()
cancel(reason)
read()
releaseLock()
}
```

#### get closed()

##### Semantics
### get closed()

Used for getting notified that the stream is closed or errored.

Expand All @@ -68,15 +36,13 @@ If the promise returned by this getter:
- rejects, that means either of:
- the stream has been errored

#### cancel(reason)

##### Semantics
### cancel(reason)

Tells the byte stream to stop generating or buffering data.

- _reason_: An object indicating the reason why the consumer lost interest

###### Return value
#### Return value

If the returned promise:
- fulfills, that means either of:
Expand All @@ -87,13 +53,11 @@ If the returned promise:
- the stream has been already errored
- the stream was cancelled for this `cancel()` call but the cancellation finished uncleanly. In this case, the stream becomes `"closed"`.

#### read()

##### Semantics
### read()

Used for reading bytes as an `ArrayBufferView` and also for getting notified that the stream is closed or errored.

###### Return value
#### Return value

If the return promise:
- fulfills with _fulfillmentValue_,
Expand All @@ -107,29 +71,11 @@ If the return promise:
- rejects, that means either of:
- the stream has been errored

##### Algorithm

1. If IsReadableByteStreamReader(**this**) is **false**, throw a **TypeError** exception.
1. If **this**@[[state]] is "closed", return a new promise resolved with CreateIterResultObject(**undefined**, *true*).
1. If **this**@[[state]] is "errored", return a new promise rejected with **this**@[[storedError]].
1. Assert: **this**@[[stream]] is not **undefined**.
1. Assert: **this**@[[stream]]@[[state]] is "readable".
1. If **this**@[[stream]] can generate a chunk to return synchronously,
1. Let _chunk_ be the chunk.
1. If _chunk_ is the final chunk to return, call-with-rethrow CloseReadableStream(*this*@[[stream]]).
1. Return a new promise resolved with CreateIterResultObject(_chunk_, **false**).
1. Otherwise,
1. Let _readRequestPromise_ be a new promise.
1. Append _readRequestPromise_ as the last element of **this**@[[readRequests]].
1. Return _readRequestPromise_.

#### releaseLock()

##### Semantics
### releaseLock()

Detaches the reader from the stream.

###### Return value and exception
#### Return value and exception

The return value of this method is void (always **undefined** if successful).

Expand All @@ -138,10 +84,10 @@ If this method returns without throwing, that means either of:
- the reader has already been released

If this method throws,
- that means that some of `read(view)` calls haven't yet been completed
- that means that some of `read()` calls haven't yet been completed
- the failure doesn't affect the state of the stream or reader

## Class ByobByteStreamReader
## ByobByteStreamReader

### Class Definition

Expand All @@ -157,25 +103,13 @@ class ByobByteStreamReader {
}
```

### Properties of the ByobByteStreamReader Prototype

#### get closed()

The same as `ReadableByteStreamReader`.

#### cancel(reason)

The same as `ReadableByteStreamReader`.

#### read(view)

##### Semantics
### read(view)

Used for reading bytes into `view` and also for getting notified that the stream is closed or errored.

- _view_: An `ArrayBufferView` to which the reader stores the bytes read from the stream

###### Return value
#### Return value

If the return promise:
- fulfills with _fulfillmentValue_,
Expand All @@ -189,7 +123,7 @@ If the return promise:
- rejects, that means either of:
- the stream has been errored

##### Algorithm
#### Algorithm draft

1. If IsReadableByteStreamReader(*this*) is *false*, throw a **TypeError** exception.
1. If **this**@[[state]] is "closed", return a new promise resolved with CreateIterResultObject(_view_, **true**).
Expand All @@ -214,7 +148,3 @@ If the return promise:
1. Let _newView_ be a new `ArrayBufferView` of the same type whose `buffer` is _view_.buffer, `byteLength` is _view_.byteLength, and `byteOffset` is _view_.byteOffset - _bytesFilled_.
1. Resolve _readRequestPromise_ with CreateIterResultObject(_newView_, *false*).
1. Return _readRequestPromise_.

#### releaseLock()

The same as `ReadableByteStreamReader`.

0 comments on commit 17a7f60

Please sign in to comment.