Skip to content

Instantly share code, notes, and snippets.

@jarakys
Created October 18, 2018 13:25
Show Gist options
  • Select an option

  • Save jarakys/e47ebf3d4f654b37cb3290b6a6a68057 to your computer and use it in GitHub Desktop.

Select an option

Save jarakys/e47ebf3d4f654b37cb3290b6a6a68057 to your computer and use it in GitHub Desktop.
using RadiYous.DependencyServices;
using RadiYous.Droid.DependencyServices;
using System.IO;
using System.Threading;
using Xamarin.Forms;
[assembly: Dependency(typeof(ImageChache))]
namespace RadiYous.Droid.DependencyServices
{
class ImageChache : IImageChache
{
public bool IsExist(string name)
{
var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), name+".txt");
Java.IO.File file = new Java.IO.File(backingFile);
var r = file.Exists();
if (backingFile == null || !File.Exists(backingFile))
{
return false;
}
return true;
}
public byte[] Load(string name)
{
var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), name + ".txt");
if (backingFile == null || !File.Exists(backingFile))
{
return null;
}
Stream reader = File.Open(backingFile, FileMode.Open);
byte[] bytesInStream = new byte[reader.Length];
reader.Read(bytesInStream, 0, bytesInStream.Length);
return bytesInStream;
}
public void Save(Stream stream, string name)
{
var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), name + ".txt");
FileStream writer = File.Create(backingFile);
byte[] bytesInStream = new byte[stream.Length];
stream.Read(bytesInStream, 0, bytesInStream.Length);
writer.Write(bytesInStream, 0, bytesInStream.Length);
writer.Close();
writer.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment