You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

node-taglib-sharp-extend

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-taglib-sharp-extend

read and write audio file metadata in memory

0.1.0
Source
npmnpm
Version published
Weekly downloads
151
556.52%
Maintainers
1
Weekly downloads
 
Created
Source

node-taglib-sharp-extend

extend node-taglib-sharp with:

  • MemoryFileAbstraction for file in memory
  • utils that parse Uint8Array / File / FileSystemFileHandle

usage

basic

built-in:

import { File, MemoryFileAbstraction } from 'node-taglib-sharp-extend'

export function getFile(fileName: string, buffer: Uint8Array | Buffer | number[]): File {
  return File.createFromAbstraction(
    new MemoryFileAbstraction(fileName, buffer),
  )
}

// `File.save` will not flush original buffer, so need function to get current buffer
export function getBuffer(metadata: File): Uint8Array | undefined {
  const abstraction = metadata.fileAbstraction
  return abstraction instanceof MemoryFileAbstraction
    ? abstraction.current()
    : undefined
}

utils

import { parseFile } from 'node-taglib-sharp-extend/utils'

async function handleChange(target: EventTarget) {
  const file = (target as HTMLInputElement)?.files?.[0]
  if (file) {
    const [
      getMetaFile,
      { flush, fetchMetadata, clear, currentBuffer, updateTag }
    ] = await parseFile(file)
    const _file = getMetaFile()
    _file.tag.album = 'test album'
    updateTag('artists', ['test artists']) // type safe
    console.log(fetchMetadata())
    flush()
    console.log(currentBuffer().byteLength)
    clear()
  }
}

polyfill

if you want to run in browser, you need to polyfill some node modules

there is a built-in vite plugin for polyfill, and need to install vite-plugin-node-polyfills

import { defineConfig } from 'vite'
import { polyfillTaglib } from 'node-taglib-sharp-extend/vite'

export default defineConfig({
  plugins: [
    // allow extra node polyfill options
    polyfillTaglib(),
  ],
})

Keywords

music-metadata

FAQs

Package last updated on 27 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts