Skip to content

Commit

Permalink
Merge pull request #2 from neilharvey/jpeg-formats
Browse files Browse the repository at this point in the history
Jpeg formats
  • Loading branch information
neilharvey authored Feb 2, 2017
2 parents 97573ff + 41f50d9 commit 7420a5a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/FileSignatures/Formats/Jfif.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace FileSignatures.Formats
{
/// <summary>
/// Specifies the format of a JPEG File Interchange Fomat (JFIF) file.
/// </summary>
public class JpegJfif : Jpeg
{
public JpegJfif() : base(new byte[] { 0xFF, 0xE0})
{
}
}
}
17 changes: 15 additions & 2 deletions src/FileSignatures/Formats/Jpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@
/// </summary>
public class Jpeg : Image
{
public Jpeg() : base(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, "image/jpeg", "jpg")
{
private static readonly byte[] soi = new byte[] {0xFF, 0xD8};
private const string mediaType = "image/jpeg";
private const string extension = "jpg";

/// <summary>
/// Initialises a new Jpeg format.
/// <summary>
public Jpeg() : base(soi, mediaType, extension) {
}

/// <summary>
/// Initialises a new Jpeg format with the specified application marker.
/// </summary>
/// <param name="marker">The 2-byte application marker used by the JPEG format.</param>
protected Jpeg(byte[] marker) : base(new byte[] { soi[0], soi[1], marker[0], marker[1]}, mediaType, extension) {
}
}
}
12 changes: 12 additions & 0 deletions src/FileSignatures/Formats/JpegExif.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace FileSignatures.Formats
{
/// <summary>
/// Specifies the format of a JPEG image containing EXIF data.
/// </summary>
public class JpegExif : Jpeg
{
public JpegExif() : base(new byte[] { 0xFF, 0xE1})
{
}
}
}
12 changes: 12 additions & 0 deletions src/FileSignatures/Formats/Spiff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace FileSignatures.Formats
{
/// <summary>
/// Specified the format of a Still Picture Interchange File Format (SPIFF) file.
/// </summary>
public class Spiff : Jpeg
{
public Spiff() : base(new byte[] { 0xFF, 0xE8 })
{
}
}
}
5 changes: 3 additions & 2 deletions src/FileSignatures/project.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"version": "1.0.0",
"version": "1.1.0-rc",
"name" : "FileSignatures",
"description": "A small library for detecting the type of a file based on header signature (also known as magic number) rather than file extension.",
"authors" : ["Neil Harvey"],
"packOptions": {
"tags": [ "File Format", "Mime Type", "Media Type", "Header", "Signature", "Detection" ],
"licenseUrl": "https://github.com/neilharvey/FileSignatures/blob/master/LICENCE",
"projectUrl": "https://github.com/neilharvey/FileSignatures/"
"projectUrl": "https://github.com/neilharvey/FileSignatures/",
"releaseNotes": "https://github.com/neilharvey/FileSignatures/releases"
},

"frameworks": {
Expand Down
5 changes: 3 additions & 2 deletions test/FileSignatures.Tests/FunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public class FunctionalTests
[InlineData("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")]
[InlineData("exe", "application/octet-stream")]
[InlineData("gif", "image/gif")]
[InlineData("jpg", "image/jpeg")]
[InlineData("jfif", "image/jpeg")]
[InlineData("exif", "image/jpeg")]
[InlineData("pdf", "application/pdf")]
[InlineData("rtf", "application/rtf")]
[InlineData("png", "image/png")]
[InlineData("ppt", "application/vnd.ms-powerpoint")]
[InlineData("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation")]
[InlineData("spiff", "image/jpeg")]
[InlineData("tif", "image/tiff")]
[InlineData("xls", "application/vnd.ms-excel")]
[InlineData("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")]
Expand All @@ -28,7 +30,6 @@ public void SamplesAreRecognised(string sample, string expected)
var result = InspectSample(sample);

Assert.NotNull(result);
Assert.Equal(sample, result.Extension);
Assert.Equal(expected, result.MediaType);
}

Expand Down
Binary file added test/FileSignatures.Tests/Samples/exif
Binary file not shown.
File renamed without changes.
Binary file added test/FileSignatures.Tests/Samples/spiff
Binary file not shown.

0 comments on commit 7420a5a

Please sign in to comment.