Skip to content

Commit 9a8b574

Browse files
author
Ciro S. Costa
committed
Introduces cast encoding and decoding methods
1 parent 993efe6 commit 9a8b574

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cast/cast.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
//
44
// The current implementation is based on the V2 format as of July 2nd, 2018.
55
//
6-
// See https://github.com/asciinema/asciinema/blob/49a892d9e6f57ab3a774c0835fa563c77cf6a7a7/doc/asciicast-v2.md.
6+
// From [1], asciicast v2 file is a newline-delimited JSON file where:
7+
//
8+
// - first line contains header (initial terminal size, timestamp and other
9+
// meta-data), encoded as JSON object; and
10+
// - all following lines form an event stream, each line representing a separate
11+
// event, encoded as 3-element JSON array.
12+
//
13+
// [1]: https://github.com/asciinema/asciinema/blob/49a892d9e6f57ab3a774c0835fa563c77cf6a7a7/doc/asciicast-v2.md.
714
package cast
815

916
import (
17+
"bufio"
1018
"encoding/json"
19+
"io"
1120
)
1221

1322
// Header represents the asciicast header - a JSON-encoded object containing
@@ -96,3 +105,15 @@ type Cast struct {
96105
// the recording.
97106
EventStream []*Event
98107
}
108+
109+
// Decode reads the whole contents of the reader passed as argument, validates
110+
// whether the stream contains a valid asciinema cast and then unmarshals it
111+
// into a cast struct.
112+
func Decode(r io.Reader) (cast *Cast, err error) {
113+
return
114+
}
115+
116+
// Encode writes the encoding of `Cast` into the writer passed as an argument.
117+
func Encode(w io.Writer, cast *Cast) (err error) {
118+
return
119+
}

cast/cast_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ import (
88
)
99

1010
var _ = Describe("Cast", func() {
11-
1211
})

0 commit comments

Comments
 (0)