From 1d1613a4e3747fc6ee85823dd31003afa53620a8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 6 Oct 2023 13:31:41 +0100 Subject: [PATCH] [IFilter] Add base implementations. --- Interfaces/IFilter.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Interfaces/IFilter.cs b/Interfaces/IFilter.cs index 03f591b..eca29c8 100644 --- a/Interfaces/IFilter.cs +++ b/Interfaces/IFilter.cs @@ -128,7 +128,7 @@ public interface IFilter /// Identifies if the specified path contains data recognizable by this filter instance /// Path. - bool Identify(string path); + bool Identify(string path) => File.Exists(path) && Identify(new FileStream(path, FileMode.Open, FileAccess.Read)); /// Identifies if the specified stream contains data recognizable by this filter instance /// Stream. @@ -136,11 +136,13 @@ public interface IFilter /// Identifies if the specified buffer contains data recognizable by this filter instance /// Buffer. - bool Identify(byte[] buffer); + bool Identify(byte[] buffer) => Identify(new MemoryStream(buffer)); /// Opens the specified path with this filter instance /// Path. - ErrorNumber Open(string path); + ErrorNumber Open(string path) => !File.Exists(path) + ? ErrorNumber.NoSuchFile + : Open(new FileStream(path, FileMode.Open, FileAccess.Read)); /// Opens the specified stream with this filter instance /// Stream. @@ -148,5 +150,5 @@ public interface IFilter /// Opens the specified buffer with this filter instance /// Buffer. - ErrorNumber Open(byte[] buffer); + ErrorNumber Open(byte[] buffer) => Open(new MemoryStream(buffer)); } \ No newline at end of file