TagLib-sharp File from ByteArray/Stream

arrays, file, taglib

Solution

Try this:

var file = TagLib.File.Create(new FileBytesAbstraction(<file name>, <file bytes>));

Where FileBytesAbstraction is:

public class FileBytesAbstraction : TagLib.File.IFileAbstraction
{
    public FileBytesAbstraction(string name, byte[] bytes)
    {
        Name = name;

        var stream = new MemoryStream(bytes);
        ReadStream = stream;
        WriteStream = stream;
    }

    public void CloseStream(Stream stream)
    {
        stream.Dispose();
    }

    public string Name { get; private set; }

    public Stream ReadStream { get; private set; }

    public Stream WriteStream { get; private set; }
}

Problem

Is it possible edit Tags of an ByteArray which represents a Mp3-File with TagLib#? At the moment I need to do it this way: ``` System.IO.File.WriteAllBytes(path + file + ".mp3", byt); TagLib.File f = TagLib.File.Create(path + song + ".mp3"); ``` Is it possible to avoid this and create the TagLib.File directly from a ByteArray?

Original source

Related problems