UNPKG

1.47 kBJavaScriptView Raw
1import {assert} from './util/assert';
2
3import {Packet} from './coders/byte-packets';
4import {FixedAsciiString, Uint8, Uint32BE} from './coders/byte-primitives';
5
6/**
7 * @augments Packet
8 */
9class SB1Signature extends Packet.extend({
10 /**
11 * 10 byte ascii string equaling `'ScratchV01'` or `'ScratchV02'`.
12 * @type {string}
13 * @memberof SB1Signature#
14 */
15 version: new FixedAsciiString(10),
16
17 /**
18 * Number of bytes in the info block.
19 * @type {number}
20 * @memberof SB1Signature#
21 */
22 infoByteLength: Uint32BE
23}) {
24 /**
25 * Is this a valid SB1Signature?
26 * @method
27 * @throws {AssertionError} Throws if it is not valid.
28 */
29 validate () {
30 assert.validate(
31 this.equals({version: 'ScratchV01'}) ||
32 this.equals({version: 'ScratchV02'}),
33 'Invalid Scratch file signature.'
34 );
35 }
36}
37
38Packet.initConstructor(SB1Signature);
39
40class SB1Header extends Packet.extend({
41 ObjS: new FixedAsciiString(4),
42 ObjSValue: Uint8,
43 Stch: new FixedAsciiString(4),
44 StchValue: Uint8,
45 numObjects: Uint32BE
46}) {
47 validate () {
48 assert.validate(
49 this.equals({
50 ObjS: 'ObjS',
51 ObjSValue: 1,
52 Stch: 'Stch',
53 StchValue: 1
54 }),
55 'Invalid Scratch file info packet header.'
56 );
57 }
58}
59
60Packet.initConstructor(SB1Header);
61
62export {SB1Signature, SB1Header};