| Total Complexity | 4 |
| Complexity/F | 1.33 |
| Lines of Code | 32 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import * as ID3Util from "../ID3Util" |
||
| 2 | import { WriteTags } from "../types/Tags" |
||
| 3 | import { isFunction } from "../util" |
||
| 4 | import { createBufferFromTags } from "../TagsHelpers" |
||
| 5 | |||
| 6 | export type CreateCallback = |
||
| 7 | (data: Buffer) => void |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Creates a buffer containing the ID3 Tag |
||
| 11 | */ |
||
| 12 | export function create(tags: WriteTags): Buffer |
||
| 13 | export function create(tags: WriteTags, callback: CreateCallback): void |
||
| 14 | export function create(tags: WriteTags, callback?: CreateCallback) { |
||
| 15 | const frames = createBufferFromTags(tags) |
||
| 16 | |||
| 17 | // Create ID3 header |
||
| 18 | const header = Buffer.alloc(10) |
||
| 19 | header.fill(0) |
||
| 20 | header.write("ID3", 0) //File identifier |
||
| 21 | header.writeUInt16BE(0x0300, 3) //Version 2.3.0 -- 03 00 |
||
| 22 | header.writeUInt16BE(0x0000, 5) //Flags 00 |
||
| 23 | ID3Util.encodeSize(frames.length).copy(header, 6) |
||
| 24 | |||
| 25 | const id3Data = Buffer.concat([header, frames]) |
||
| 26 | |||
| 27 | if (isFunction(callback)) { |
||
| 28 | return callback(id3Data) |
||
| 29 | } |
||
| 30 | return id3Data |
||
| 31 | } |
||
| 32 |