Completed
Push — master ( 61d444...b3f358 )
by Jan
16s queued 14s
created

src/frames/frame-comm.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 29
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 21
mnd 1
bc 1
fnc 0
dl 0
loc 29
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { FrameBuilder } from "../FrameBuilder"
2
import { FrameReader } from "../FrameReader"
3
import type { Data } from "./type"
4
5
export const COMM = {
6
    create: (data: Data) => {
7
        data = data || {}
8
        if(!data.text) {
9
            return null
10
        }
11
12
        return new FrameBuilder("COMM")
13
            .appendNumber(0x01, 1)
14
            .appendValue(data.language)
15
            .appendNullTerminatedValue(data.shortText, 0x01)
16
            .appendValue(data.text, null, 0x01)
17
            .getBuffer()
18
    },
19
    read: (buffer: Buffer) => {
20
        const reader = new FrameReader(buffer, 0)
21
22
        return {
23
            language: reader.consumeStaticValue('string', 3, 0x00),
24
            shortText: reader.consumeNullTerminatedValue('string'),
25
            text: reader.consumeStaticValue('string', null)
26
        }
27
    }
28
}
29