TonyValenti / Mime-Detective-clarkis117

Mime type detector for files, byte arrays, and streams, .NET Standard Fork
MIT License
38 stars 9 forks source link

Detecting .doc and .xls file using the StreamExtensions or ByteArrayExtensions #25

Open melucas opened 6 years ago

melucas commented 6 years ago

When loading a old Microsoft Office file into a stream or byte array, the GetFileType() resulting MimeType is doc,ppt,xls, not the expect xls or doc.

For example. Both text fail.

    [Fact]
    public void CanReadExcelFileFromByteArray()
    {
        var result = File.ReadAllBytes("./data/Documents/XlsExcel2007.xls").GetFileType();

        Assert.NotNull(result);
        Assert.Equal(MimeTypes.EXCEL, result);
    }

    [Fact]
    public void CanReadExcelFileFromStream()
    {
        using (FileStream stream = File.Open("./data/Documents/XlsExcel2007.xls", FileMode.Open))
        {
            var result = stream.GetFileType(false, true);

            Assert.NotNull(result);
            Assert.Equal(MimeTypes.EXCEL, result);
        }
    }

Any ideas how to get this to work without having to save the files to disk and then loading them using the FileInfo object?