for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import { WriteTags } from "../types/Tags"
import { Options } from "../types/Options"
import { isFunction, isString } from "../util"
import { read } from "./read"
import { updateTags } from '../updateTags'
import { write, WriteCallback } from "./write"
/**
* Update ID3-Tags from passed buffer/filepath
*/
export function update(
tags: WriteTags,
buffer: Buffer,
options?: Options
): Buffer
filepath: string,
): true | Error
filebuffer: string | Buffer,
callback: WriteCallback
): void
options: Options,
optionsOrCallback?: Options | WriteCallback,
callback?: WriteCallback
): Buffer | true | Error | void {
const options: Options =
(isFunction(optionsOrCallback) ? {} : optionsOrCallback) ?? {}
callback =
isFunction(optionsOrCallback) ? optionsOrCallback : callback
const currentTags = read(filebuffer, options)
const updatedTags = updateTags(tags, currentTags)
if (isFunction(callback)) {
return write(updatedTags, filebuffer, callback)
}
if (isString(filebuffer)) {
return write(updatedTags, filebuffer)