2016-11-12 17:02:48 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2017-06-21 00:19:47 +02:00
|
|
|
|
namespace SonicAudioLib.FileBases
|
2016-11-12 17:02:48 +01:00
|
|
|
|
{
|
2017-06-21 00:19:47 +02:00
|
|
|
|
public abstract class FileBase
|
2016-11-12 17:02:48 +01:00
|
|
|
|
{
|
2017-04-23 18:22:25 +02:00
|
|
|
|
protected int bufferSize = 4096;
|
|
|
|
|
|
2016-11-12 17:02:48 +01:00
|
|
|
|
public abstract void Read(Stream source);
|
|
|
|
|
public abstract void Write(Stream destination);
|
|
|
|
|
|
2017-04-17 18:06:29 +02:00
|
|
|
|
public virtual void Load(string sourceFileName, int bufferSize)
|
2016-11-12 17:02:48 +01:00
|
|
|
|
{
|
2017-04-17 18:06:29 +02:00
|
|
|
|
using (Stream source = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize))
|
2016-11-12 17:02:48 +01:00
|
|
|
|
{
|
|
|
|
|
Read(source);
|
|
|
|
|
}
|
2017-04-23 18:22:25 +02:00
|
|
|
|
|
|
|
|
|
this.bufferSize = bufferSize;
|
2016-11-12 17:02:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-17 18:06:29 +02:00
|
|
|
|
public virtual void Load(string sourceFileName)
|
|
|
|
|
{
|
|
|
|
|
Load(sourceFileName, 4096);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 17:02:48 +01:00
|
|
|
|
public virtual void Load(byte[] sourceByteArray)
|
|
|
|
|
{
|
|
|
|
|
using (Stream source = new MemoryStream(sourceByteArray))
|
|
|
|
|
{
|
|
|
|
|
Read(source);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Save(string destinationFileName)
|
|
|
|
|
{
|
2017-04-17 18:06:29 +02:00
|
|
|
|
Save(destinationFileName, 4096);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Save(string destinationFileName, int bufferSize)
|
|
|
|
|
{
|
|
|
|
|
using (Stream destination = File.Create(destinationFileName, bufferSize))
|
2016-11-12 17:02:48 +01:00
|
|
|
|
{
|
|
|
|
|
Write(destination);
|
|
|
|
|
}
|
2017-04-23 18:22:25 +02:00
|
|
|
|
|
|
|
|
|
this.bufferSize = bufferSize;
|
2016-11-12 17:02:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual byte[] Save()
|
|
|
|
|
{
|
|
|
|
|
using (MemoryStream destination = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
Write(destination);
|
|
|
|
|
return destination.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|