| Total Complexity | 11 |
| Complexity/F | 2.2 |
| Lines of Code | 53 |
| Function Count | 5 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { WriteTags } from "../types/Tags" |
||
| 2 | import { Options } from "../types/Options" |
||
| 3 | import { isFunction, isString } from "../util" |
||
| 4 | import { read } from "./read" |
||
| 5 | import { updateTags } from '../updateTags' |
||
| 6 | import { write, WriteCallback } from "./write" |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Update ID3-Tags from passed buffer/filepath |
||
| 10 | */ |
||
| 11 | export function update( |
||
| 12 | tags: WriteTags, |
||
| 13 | buffer: Buffer, |
||
| 14 | options?: Options |
||
| 15 | ): Buffer |
||
| 16 | export function update( |
||
| 17 | tags: WriteTags, |
||
| 18 | filepath: string, |
||
| 19 | options?: Options |
||
| 20 | ): true | Error |
||
| 21 | export function update( |
||
| 22 | tags: WriteTags, |
||
| 23 | filebuffer: string | Buffer, |
||
| 24 | callback: WriteCallback |
||
| 25 | ): void |
||
| 26 | export function update( |
||
| 27 | tags: WriteTags, |
||
| 28 | filebuffer: string | Buffer, |
||
| 29 | options: Options, |
||
| 30 | callback: WriteCallback |
||
| 31 | ): void |
||
| 32 | export function update( |
||
| 33 | tags: WriteTags, |
||
| 34 | filebuffer: string | Buffer, |
||
| 35 | optionsOrCallback?: Options | WriteCallback, |
||
| 36 | callback?: WriteCallback |
||
| 37 | ): Buffer | true | Error | void { |
||
| 38 | const options: Options = |
||
| 39 | (isFunction(optionsOrCallback) ? {} : optionsOrCallback) ?? {} |
||
| 40 | callback = |
||
| 41 | isFunction(optionsOrCallback) ? optionsOrCallback : callback |
||
| 42 | |||
| 43 | const currentTags = read(filebuffer, options) |
||
| 44 | const updatedTags = updateTags(tags, currentTags) |
||
| 45 | if (isFunction(callback)) { |
||
| 46 | return write(updatedTags, filebuffer, callback) |
||
| 47 | } |
||
| 48 | if (isString(filebuffer)) { |
||
| 49 | return write(updatedTags, filebuffer) |
||
| 50 | } |
||
| 51 | return write(updatedTags, filebuffer) |
||
| 52 | } |
||
| 53 |