├── .gitignore ├── Configurations ├── Debug.xcconfig ├── Magic.xcconfig ├── MagicTests.xcconfig ├── Release.xcconfig └── Shared.xcconfig ├── LICENSE ├── Magic.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── Magic.xcscheme ├── Magic ├── Info.plist ├── Magic.h ├── Magic.swift └── module.modulemap ├── MagicTests ├── Info.plist └── MagicTests.swift ├── README.md ├── Scripts └── build_deps.sh ├── Vendor └── magic │ ├── include │ ├── .gitkeep │ └── magic.h │ ├── lib │ ├── .gitkeep │ └── libmagic.a │ ├── module.modulemap │ └── share │ └── misc │ ├── .gitkeep │ └── magic.mgc └── swift-magic.podspec /.gitignore: -------------------------------------------------------------------------------- 1 | ### https://raw.github.com/github/gitignore/c68eb91e0a72ca1efba128c33de9caea41281f19/Global/macOS.gitignore 2 | 3 | # General 4 | .DS_Store 5 | .AppleDouble 6 | .LSOverride 7 | 8 | # Icon must end with two \r 9 | Icon 10 | 11 | # Thumbnails 12 | ._* 13 | 14 | # Files that might appear in the root of a volume 15 | .DocumentRevisions-V100 16 | .fseventsd 17 | .Spotlight-V100 18 | .TemporaryItems 19 | .Trashes 20 | .VolumeIcon.icns 21 | .com.apple.timemachine.donotpresent 22 | 23 | # Directories potentially created on remote AFP share 24 | .AppleDB 25 | .AppleDesktop 26 | Network Trash Folder 27 | Temporary Items 28 | .apdisk 29 | 30 | 31 | ### https://raw.github.com/github/gitignore/c68eb91e0a72ca1efba128c33de9caea41281f19/Swift.gitignore 32 | 33 | # Xcode 34 | # 35 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 36 | 37 | ## Build generated 38 | build/ 39 | DerivedData/ 40 | 41 | ## Various settings 42 | *.pbxuser 43 | !default.pbxuser 44 | *.mode1v3 45 | !default.mode1v3 46 | *.mode2v3 47 | !default.mode2v3 48 | *.perspectivev3 49 | !default.perspectivev3 50 | xcuserdata/ 51 | 52 | ## Other 53 | *.moved-aside 54 | *.xccheckout 55 | *.xcscmblueprint 56 | 57 | ## Obj-C/Swift specific 58 | *.hmap 59 | *.ipa 60 | *.dSYM.zip 61 | *.dSYM 62 | 63 | ## Playgrounds 64 | timeline.xctimeline 65 | playground.xcworkspace 66 | 67 | # Swift Package Manager 68 | # 69 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 70 | # Packages/ 71 | # Package.pins 72 | # Package.resolved 73 | .build/ 74 | 75 | # CocoaPods 76 | # 77 | # We recommend against adding the Pods directory to your .gitignore. However 78 | # you should judge for yourself, the pros and cons are mentioned at: 79 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 80 | # 81 | # Pods/ 82 | # 83 | # Add this line if you want to avoid checking in source code from the Xcode workspace 84 | # *.xcworkspace 85 | 86 | # Carthage 87 | # 88 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 89 | # Carthage/Checkouts 90 | 91 | Carthage/Build 92 | 93 | # fastlane 94 | # 95 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 96 | # screenshots whenever they are needed. 97 | # For more information about the recommended setup visit: 98 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 99 | 100 | fastlane/report.xml 101 | fastlane/Preview.html 102 | fastlane/screenshots/**/*.png 103 | fastlane/test_output 104 | 105 | # Code Injection 106 | # 107 | # After new code Injection tools there's a generated folder /iOSInjectionProject 108 | # https://github.com/johnno1962/injectionforxcode 109 | 110 | iOSInjectionProject/ 111 | 112 | 113 | -------------------------------------------------------------------------------- /Configurations/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Shared.xcconfig" 2 | 3 | DEBUG_INFORMATION_FORMAT = dwarf 4 | ENABLE_TESTABILITY = YES 5 | GCC_DYNAMIC_NO_PIC = NO 6 | GCC_OPTIMIZATION_LEVEL = 0 7 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 $(inherited) 8 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE 9 | ONLY_ACTIVE_ARCH = YES 10 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG 11 | SWIFT_OPTIMIZATION_LEVEL = -Onone 12 | -------------------------------------------------------------------------------- /Configurations/Magic.xcconfig: -------------------------------------------------------------------------------- 1 | APPLICATION_EXTENSION_API_ONLY = YES 2 | CLANG_ENABLE_MODULES = YES 3 | CODE_SIGN_IDENTITY = 4 | CODE_SIGN_STYLE = Automatic 5 | DEFINES_MODULE = YES 6 | DEVELOPMENT_TEAM = 27AEDK3C9F 7 | DYLIB_COMPATIBILITY_VERSION = 1 8 | DYLIB_CURRENT_VERSION = 1 9 | DYLIB_INSTALL_NAME_BASE = @rpath 10 | INFOPLIST_FILE = Magic/Info.plist 11 | INSTALL_PATH = $(LOCAL_LIBRARY_DIR)/Frameworks 12 | MODULEMAP_FILE = $(SRCROOT)/Magic/module.modulemap 13 | PRODUCT_BUNDLE_IDENTIFIER = com.kishikawakatsumi.Magic 14 | PRODUCT_NAME = $(TARGET_NAME:c99extidentifier) 15 | SKIP_INSTALL = YES 16 | SWIFT_VERSION = 4.2 17 | 18 | SUPPORTED_PLATFORMS = iphoneos iphonesimulator 19 | TARGETED_DEVICE_FAMILY = 1,2 20 | IPHONEOS_DEPLOYMENT_TARGET = 8.0 21 | LIBRARY_SEARCH_PATHS = $(SRCROOT)/Vendor/magic/lib 22 | LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks 23 | ENABLE_BITCODE = YES 24 | -------------------------------------------------------------------------------- /Configurations/MagicTests.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | CODE_SIGN_STYLE = Automatic 3 | DEVELOPMENT_TEAM = 27AEDK3C9F 4 | INFOPLIST_FILE = MagicTests/Info.plist 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks 6 | PRODUCT_BUNDLE_IDENTIFIER = com.kishikawakatsumi.MagicTests 7 | PRODUCT_NAME = $(TARGET_NAME) 8 | SWIFT_VERSION = 4.2 9 | TARGETED_DEVICE_FAMILY = 1,2 10 | -------------------------------------------------------------------------------- /Configurations/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Shared.xcconfig" 2 | 3 | DEBUG_INFORMATION_FORMAT = dwarf-with-dsym 4 | ENABLE_NS_ASSERTIONS = NO 5 | MTL_ENABLE_DEBUG_INFO = NO 6 | SWIFT_COMPILATION_MODE = wholemodule 7 | SWIFT_OPTIMIZATION_LEVEL = -O 8 | VALIDATE_PRODUCT = YES 9 | -------------------------------------------------------------------------------- /Configurations/Shared.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_SEARCH_USER_PATHS = NO 2 | CLANG_ANALYZER_NONNULL = YES 3 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE 4 | CLANG_CXX_LANGUAGE_STANDARD = gnu++14 5 | CLANG_CXX_LIBRARY = libc++ 6 | CLANG_ENABLE_MODULES = YES 7 | CLANG_ENABLE_OBJC_ARC = YES 8 | CLANG_ENABLE_OBJC_WEAK = YES 9 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 10 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES 11 | CLANG_WARN_BOOL_CONVERSION = YES 12 | CLANG_WARN_COMMA = YES 13 | CLANG_WARN_CONSTANT_CONVERSION = YES 14 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES 15 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR 16 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES 17 | CLANG_WARN_EMPTY_BODY = YES 18 | CLANG_WARN_ENUM_CONVERSION = YES 19 | CLANG_WARN_INFINITE_RECURSION = YES 20 | CLANG_WARN_INT_CONVERSION = YES 21 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES 22 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 23 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES 24 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR 25 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES 26 | CLANG_WARN_STRICT_PROTOTYPES = YES 27 | CLANG_WARN_SUSPICIOUS_MOVE = YES 28 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 29 | CLANG_WARN_UNREACHABLE_CODE = YES 30 | CODE_SIGN_IDENTITY = iPhone Developer 31 | COPY_PHASE_STRIP = NO 32 | CURRENT_PROJECT_VERSION = 1 33 | ENABLE_STRICT_OBJC_MSGSEND = YES 34 | GCC_C_LANGUAGE_STANDARD = gnu11 35 | GCC_NO_COMMON_BLOCKS = YES 36 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES 37 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR 38 | GCC_WARN_UNDECLARED_SELECTOR = YES 39 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE 40 | GCC_WARN_UNUSED_FUNCTION = YES 41 | GCC_WARN_UNUSED_VARIABLE = YES 42 | IPHONEOS_DEPLOYMENT_TARGET = 8.0 43 | MTL_FAST_MATH = YES 44 | SDKROOT = iphoneos 45 | VERSION_INFO_PREFIX = 46 | VERSIONING_SYSTEM = apple-generic 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | === This project is a wrapper around libmagic. libmagic is subject to the BSD licence. Please refer to libmagic/COPYING for further information. === 2 | 3 | Copyright (c) 2018, Kishikawa Katsumi 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /Magic.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 149975EF21CE8A2C00B72A49 /* Magic.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 149975E521CE8A2C00B72A49 /* Magic.framework */; }; 11 | 149975F421CE8A2C00B72A49 /* MagicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 149975F321CE8A2C00B72A49 /* MagicTests.swift */; }; 12 | 149975F621CE8A2C00B72A49 /* Magic.h in Headers */ = {isa = PBXBuildFile; fileRef = 149975E821CE8A2C00B72A49 /* Magic.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | 1499760021CE8A6400B72A49 /* Magic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 149975FF21CE8A6400B72A49 /* Magic.swift */; }; 14 | 14D2ED2321CFE3A100693940 /* magic.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 14D2ED1A21CFE38B00693940 /* magic.h */; }; 15 | 14D2ED2421CFE3A700693940 /* magic.mgc in Resources */ = {isa = PBXBuildFile; fileRef = 14D2ED2221CFE38B00693940 /* magic.mgc */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXContainerItemProxy section */ 19 | 149975F021CE8A2C00B72A49 /* PBXContainerItemProxy */ = { 20 | isa = PBXContainerItemProxy; 21 | containerPortal = 149975DC21CE8A2C00B72A49 /* Project object */; 22 | proxyType = 1; 23 | remoteGlobalIDString = 149975E421CE8A2C00B72A49; 24 | remoteInfo = Magic; 25 | }; 26 | /* End PBXContainerItemProxy section */ 27 | 28 | /* Begin PBXCopyFilesBuildPhase section */ 29 | 14D2EC6821CFC8DC00693940 /* CopyFiles */ = { 30 | isa = PBXCopyFilesBuildPhase; 31 | buildActionMask = 12; 32 | dstPath = include/magic; 33 | dstSubfolderSpec = 6; 34 | files = ( 35 | 14D2ED2321CFE3A100693940 /* magic.h in CopyFiles */, 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXCopyFilesBuildPhase section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | 149975E521CE8A2C00B72A49 /* Magic.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Magic.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 149975E821CE8A2C00B72A49 /* Magic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Magic.h; sourceTree = ""; }; 44 | 149975E921CE8A2C00B72A49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 149975EE21CE8A2C00B72A49 /* MagicTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MagicTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | 149975F321CE8A2C00B72A49 /* MagicTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MagicTests.swift; sourceTree = ""; }; 47 | 149975F521CE8A2C00B72A49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | 149975FF21CE8A6400B72A49 /* Magic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Magic.swift; sourceTree = ""; }; 49 | 14C397F721CEB01200E6236D /* Magic.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Magic.xcconfig; sourceTree = ""; }; 50 | 14C397F821CEB04D00E6236D /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; 51 | 14C397F921CEB05700E6236D /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; 52 | 14C397FC21CEB36500E6236D /* MagicTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = MagicTests.xcconfig; sourceTree = ""; }; 53 | 14D2ED1A21CFE38B00693940 /* magic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = magic.h; sourceTree = ""; }; 54 | 14D2ED1E21CFE38B00693940 /* libmagic.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libmagic.a; sourceTree = ""; }; 55 | 14D2ED2221CFE38B00693940 /* magic.mgc */ = {isa = PBXFileReference; lastKnownFileType = file; path = magic.mgc; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | 149975E221CE8A2C00B72A49 /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | 149975EB21CE8A2C00B72A49 /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | 149975EF21CE8A2C00B72A49 /* Magic.framework in Frameworks */, 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | 149975DB21CE8A2C00B72A49 = { 78 | isa = PBXGroup; 79 | children = ( 80 | 149975E721CE8A2C00B72A49 /* Magic */, 81 | 149975F221CE8A2C00B72A49 /* MagicTests */, 82 | 14C397FB21CEB07C00E6236D /* Configurations */, 83 | 14D2ED1721CFE38B00693940 /* Vendor */, 84 | 149975E621CE8A2C00B72A49 /* Products */, 85 | ); 86 | sourceTree = ""; 87 | }; 88 | 149975E621CE8A2C00B72A49 /* Products */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 149975E521CE8A2C00B72A49 /* Magic.framework */, 92 | 149975EE21CE8A2C00B72A49 /* MagicTests.xctest */, 93 | ); 94 | name = Products; 95 | sourceTree = ""; 96 | }; 97 | 149975E721CE8A2C00B72A49 /* Magic */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 149975E821CE8A2C00B72A49 /* Magic.h */, 101 | 149975FF21CE8A6400B72A49 /* Magic.swift */, 102 | 149975E921CE8A2C00B72A49 /* Info.plist */, 103 | ); 104 | path = Magic; 105 | sourceTree = ""; 106 | }; 107 | 149975F221CE8A2C00B72A49 /* MagicTests */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 149975F321CE8A2C00B72A49 /* MagicTests.swift */, 111 | 149975F521CE8A2C00B72A49 /* Info.plist */, 112 | ); 113 | path = MagicTests; 114 | sourceTree = ""; 115 | }; 116 | 14C397FB21CEB07C00E6236D /* Configurations */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 14C397F821CEB04D00E6236D /* Debug.xcconfig */, 120 | 14C397F921CEB05700E6236D /* Release.xcconfig */, 121 | 14C397F721CEB01200E6236D /* Magic.xcconfig */, 122 | 14C397FC21CEB36500E6236D /* MagicTests.xcconfig */, 123 | ); 124 | path = Configurations; 125 | sourceTree = ""; 126 | }; 127 | 14D2ED1721CFE38B00693940 /* Vendor */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 14D2ED1821CFE38B00693940 /* magic */, 131 | ); 132 | path = Vendor; 133 | sourceTree = ""; 134 | }; 135 | 14D2ED1821CFE38B00693940 /* magic */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | 14D2ED1921CFE38B00693940 /* include */, 139 | 14D2ED1C21CFE38B00693940 /* lib */, 140 | 14D2ED1F21CFE38B00693940 /* share */, 141 | ); 142 | path = magic; 143 | sourceTree = ""; 144 | }; 145 | 14D2ED1921CFE38B00693940 /* include */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | 14D2ED1A21CFE38B00693940 /* magic.h */, 149 | ); 150 | path = include; 151 | sourceTree = ""; 152 | }; 153 | 14D2ED1C21CFE38B00693940 /* lib */ = { 154 | isa = PBXGroup; 155 | children = ( 156 | 14D2ED1E21CFE38B00693940 /* libmagic.a */, 157 | ); 158 | path = lib; 159 | sourceTree = ""; 160 | }; 161 | 14D2ED1F21CFE38B00693940 /* share */ = { 162 | isa = PBXGroup; 163 | children = ( 164 | 14D2ED2021CFE38B00693940 /* misc */, 165 | ); 166 | path = share; 167 | sourceTree = ""; 168 | }; 169 | 14D2ED2021CFE38B00693940 /* misc */ = { 170 | isa = PBXGroup; 171 | children = ( 172 | 14D2ED2221CFE38B00693940 /* magic.mgc */, 173 | ); 174 | path = misc; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXGroup section */ 178 | 179 | /* Begin PBXHeadersBuildPhase section */ 180 | 149975E021CE8A2C00B72A49 /* Headers */ = { 181 | isa = PBXHeadersBuildPhase; 182 | buildActionMask = 2147483647; 183 | files = ( 184 | 149975F621CE8A2C00B72A49 /* Magic.h in Headers */, 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | }; 188 | /* End PBXHeadersBuildPhase section */ 189 | 190 | /* Begin PBXNativeTarget section */ 191 | 149975E421CE8A2C00B72A49 /* Magic */ = { 192 | isa = PBXNativeTarget; 193 | buildConfigurationList = 149975F921CE8A2C00B72A49 /* Build configuration list for PBXNativeTarget "Magic" */; 194 | buildPhases = ( 195 | 149975E021CE8A2C00B72A49 /* Headers */, 196 | 14D2EC6821CFC8DC00693940 /* CopyFiles */, 197 | 149975E121CE8A2C00B72A49 /* Sources */, 198 | 149975E221CE8A2C00B72A49 /* Frameworks */, 199 | 149975E321CE8A2C00B72A49 /* Resources */, 200 | ); 201 | buildRules = ( 202 | ); 203 | dependencies = ( 204 | ); 205 | name = Magic; 206 | productName = Magic; 207 | productReference = 149975E521CE8A2C00B72A49 /* Magic.framework */; 208 | productType = "com.apple.product-type.framework"; 209 | }; 210 | 149975ED21CE8A2C00B72A49 /* MagicTests */ = { 211 | isa = PBXNativeTarget; 212 | buildConfigurationList = 149975FC21CE8A2C00B72A49 /* Build configuration list for PBXNativeTarget "MagicTests" */; 213 | buildPhases = ( 214 | 149975EA21CE8A2C00B72A49 /* Sources */, 215 | 149975EB21CE8A2C00B72A49 /* Frameworks */, 216 | 149975EC21CE8A2C00B72A49 /* Resources */, 217 | ); 218 | buildRules = ( 219 | ); 220 | dependencies = ( 221 | 149975F121CE8A2C00B72A49 /* PBXTargetDependency */, 222 | ); 223 | name = MagicTests; 224 | productName = MagicTests; 225 | productReference = 149975EE21CE8A2C00B72A49 /* MagicTests.xctest */; 226 | productType = "com.apple.product-type.bundle.unit-test"; 227 | }; 228 | /* End PBXNativeTarget section */ 229 | 230 | /* Begin PBXProject section */ 231 | 149975DC21CE8A2C00B72A49 /* Project object */ = { 232 | isa = PBXProject; 233 | attributes = { 234 | LastSwiftUpdateCheck = 1000; 235 | LastUpgradeCheck = 1000; 236 | ORGANIZATIONNAME = "Kishikawa Katsumi"; 237 | TargetAttributes = { 238 | 149975E421CE8A2C00B72A49 = { 239 | CreatedOnToolsVersion = 10.0; 240 | LastSwiftMigration = 1000; 241 | }; 242 | 149975ED21CE8A2C00B72A49 = { 243 | CreatedOnToolsVersion = 10.0; 244 | }; 245 | }; 246 | }; 247 | buildConfigurationList = 149975DF21CE8A2C00B72A49 /* Build configuration list for PBXProject "Magic" */; 248 | compatibilityVersion = "Xcode 9.3"; 249 | developmentRegion = en; 250 | hasScannedForEncodings = 0; 251 | knownRegions = ( 252 | en, 253 | ); 254 | mainGroup = 149975DB21CE8A2C00B72A49; 255 | productRefGroup = 149975E621CE8A2C00B72A49 /* Products */; 256 | projectDirPath = ""; 257 | projectRoot = ""; 258 | targets = ( 259 | 149975E421CE8A2C00B72A49 /* Magic */, 260 | 149975ED21CE8A2C00B72A49 /* MagicTests */, 261 | ); 262 | }; 263 | /* End PBXProject section */ 264 | 265 | /* Begin PBXResourcesBuildPhase section */ 266 | 149975E321CE8A2C00B72A49 /* Resources */ = { 267 | isa = PBXResourcesBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | 14D2ED2421CFE3A700693940 /* magic.mgc in Resources */, 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | 149975EC21CE8A2C00B72A49 /* Resources */ = { 275 | isa = PBXResourcesBuildPhase; 276 | buildActionMask = 2147483647; 277 | files = ( 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | /* End PBXResourcesBuildPhase section */ 282 | 283 | /* Begin PBXSourcesBuildPhase section */ 284 | 149975E121CE8A2C00B72A49 /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | 1499760021CE8A6400B72A49 /* Magic.swift in Sources */, 289 | ); 290 | runOnlyForDeploymentPostprocessing = 0; 291 | }; 292 | 149975EA21CE8A2C00B72A49 /* Sources */ = { 293 | isa = PBXSourcesBuildPhase; 294 | buildActionMask = 2147483647; 295 | files = ( 296 | 149975F421CE8A2C00B72A49 /* MagicTests.swift in Sources */, 297 | ); 298 | runOnlyForDeploymentPostprocessing = 0; 299 | }; 300 | /* End PBXSourcesBuildPhase section */ 301 | 302 | /* Begin PBXTargetDependency section */ 303 | 149975F121CE8A2C00B72A49 /* PBXTargetDependency */ = { 304 | isa = PBXTargetDependency; 305 | target = 149975E421CE8A2C00B72A49 /* Magic */; 306 | targetProxy = 149975F021CE8A2C00B72A49 /* PBXContainerItemProxy */; 307 | }; 308 | /* End PBXTargetDependency section */ 309 | 310 | /* Begin XCBuildConfiguration section */ 311 | 149975F721CE8A2C00B72A49 /* Debug */ = { 312 | isa = XCBuildConfiguration; 313 | baseConfigurationReference = 14C397F821CEB04D00E6236D /* Debug.xcconfig */; 314 | buildSettings = { 315 | }; 316 | name = Debug; 317 | }; 318 | 149975F821CE8A2C00B72A49 /* Release */ = { 319 | isa = XCBuildConfiguration; 320 | baseConfigurationReference = 14C397F921CEB05700E6236D /* Release.xcconfig */; 321 | buildSettings = { 322 | }; 323 | name = Release; 324 | }; 325 | 149975FA21CE8A2C00B72A49 /* Debug */ = { 326 | isa = XCBuildConfiguration; 327 | baseConfigurationReference = 14C397F721CEB01200E6236D /* Magic.xcconfig */; 328 | buildSettings = { 329 | }; 330 | name = Debug; 331 | }; 332 | 149975FB21CE8A2C00B72A49 /* Release */ = { 333 | isa = XCBuildConfiguration; 334 | baseConfigurationReference = 14C397F721CEB01200E6236D /* Magic.xcconfig */; 335 | buildSettings = { 336 | }; 337 | name = Release; 338 | }; 339 | 149975FD21CE8A2C00B72A49 /* Debug */ = { 340 | isa = XCBuildConfiguration; 341 | baseConfigurationReference = 14C397FC21CEB36500E6236D /* MagicTests.xcconfig */; 342 | buildSettings = { 343 | }; 344 | name = Debug; 345 | }; 346 | 149975FE21CE8A2C00B72A49 /* Release */ = { 347 | isa = XCBuildConfiguration; 348 | baseConfigurationReference = 14C397FC21CEB36500E6236D /* MagicTests.xcconfig */; 349 | buildSettings = { 350 | }; 351 | name = Release; 352 | }; 353 | /* End XCBuildConfiguration section */ 354 | 355 | /* Begin XCConfigurationList section */ 356 | 149975DF21CE8A2C00B72A49 /* Build configuration list for PBXProject "Magic" */ = { 357 | isa = XCConfigurationList; 358 | buildConfigurations = ( 359 | 149975F721CE8A2C00B72A49 /* Debug */, 360 | 149975F821CE8A2C00B72A49 /* Release */, 361 | ); 362 | defaultConfigurationIsVisible = 0; 363 | defaultConfigurationName = Release; 364 | }; 365 | 149975F921CE8A2C00B72A49 /* Build configuration list for PBXNativeTarget "Magic" */ = { 366 | isa = XCConfigurationList; 367 | buildConfigurations = ( 368 | 149975FA21CE8A2C00B72A49 /* Debug */, 369 | 149975FB21CE8A2C00B72A49 /* Release */, 370 | ); 371 | defaultConfigurationIsVisible = 0; 372 | defaultConfigurationName = Release; 373 | }; 374 | 149975FC21CE8A2C00B72A49 /* Build configuration list for PBXNativeTarget "MagicTests" */ = { 375 | isa = XCConfigurationList; 376 | buildConfigurations = ( 377 | 149975FD21CE8A2C00B72A49 /* Debug */, 378 | 149975FE21CE8A2C00B72A49 /* Release */, 379 | ); 380 | defaultConfigurationIsVisible = 0; 381 | defaultConfigurationName = Release; 382 | }; 383 | /* End XCConfigurationList section */ 384 | }; 385 | rootObject = 149975DC21CE8A2C00B72A49 /* Project object */; 386 | } 387 | -------------------------------------------------------------------------------- /Magic.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Magic.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Magic.xcodeproj/xcshareddata/xcschemes/Magic.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Magic/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.5.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /Magic/Magic.h: -------------------------------------------------------------------------------- 1 | // 2 | // Magic.h 3 | // Magic 4 | // 5 | // Created by Kishikawa Katsumi on 2018/12/23. 6 | // Copyright © 2018 Kishikawa Katsumi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | FOUNDATION_EXPORT double MagicVersionNumber; 12 | FOUNDATION_EXPORT const unsigned char MagicVersionString[]; 13 | -------------------------------------------------------------------------------- /Magic/Magic.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Magic.swift 3 | // Magic 4 | // 5 | // Created by Kishikawa Katsumi on 2018/12/23. 6 | // Copyright © 2018 Kishikawa Katsumi. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import cmagic 11 | 12 | public final class Magic { 13 | public static let shared = Magic() 14 | private let magic: magic_t 15 | 16 | public init() { 17 | guard let path = Bundle(for: Magic.self).path(forResource: "magic", ofType: "mgc") else { 18 | fatalError("'magic.mgc' is not found in bundle") 19 | } 20 | magic = magic_open(MAGIC_NONE) 21 | magic_load(magic, NSString(string: path).fileSystemRepresentation) 22 | } 23 | 24 | deinit { 25 | magic_close(magic) 26 | } 27 | 28 | public func file(_ path: URL) throws -> String { 29 | return try file(path, flags: .none) 30 | } 31 | 32 | public func file(_ path: URL, flags: Flags) throws -> String { 33 | magic_setflags(magic, flags.rawValue) 34 | 35 | guard FileManager().fileExists(atPath: path.path) else { 36 | throw Error.notFound 37 | } 38 | guard let description = magic_file(magic, (path as NSURL).fileSystemRepresentation) else { 39 | throw Error.unexpected 40 | } 41 | 42 | return String(cString: description) 43 | } 44 | 45 | public struct Flags: OptionSet { 46 | public let rawValue: Int32 47 | 48 | public init(rawValue: Int32) { 49 | self.rawValue = rawValue 50 | } 51 | 52 | public static let none = Flags(rawValue: MAGIC_NONE) /* No flags */ 53 | public static let debug = Flags(rawValue: MAGIC_DEBUG) /* Turn on debugging */ 54 | public static let symlink = Flags(rawValue: MAGIC_SYMLINK) /* Follow symlinks */ 55 | public static let compress = Flags(rawValue: MAGIC_COMPRESS) /* Check inside compressed files */ 56 | public static let devices = Flags(rawValue: MAGIC_DEVICES) /* Look at the contents of devices */ 57 | public static let mimeType = Flags(rawValue: MAGIC_MIME_TYPE) /* Return the MIME type */ 58 | public static let preserveAtime = Flags(rawValue: MAGIC_PRESERVE_ATIME) /* Restore access time on exit */ 59 | public static let mimeEncoding = Flags(rawValue: MAGIC_MIME_ENCODING) /* Return the MIME encoding */ 60 | public static let mime: Flags = [mimeType, mimeEncoding] 61 | public static let apple = Flags(rawValue: MAGIC_APPLE) /* Return the Apple creator/type */ 62 | public static let `extension` = Flags(rawValue: MAGIC_EXTENSION) /* Return a /-separated list of 63 | * extensions */ 64 | public static let compressTransp = Flags(rawValue: MAGIC_COMPRESS_TRANSP) /* Check inside compressed files 65 | * but not report compression */ 66 | public static let nodesc: Flags = [`extension`, mime, apple] 67 | } 68 | 69 | public enum Error: Swift.Error { 70 | case notFound 71 | case unexpected 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Magic/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module Magic { 2 | umbrella header "Magic.h" 3 | 4 | export * 5 | module * {export *} 6 | } 7 | 8 | module cmagic { 9 | header "include/magic/magic.h" 10 | link "magic" 11 | link "z" 12 | } 13 | -------------------------------------------------------------------------------- /MagicTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /MagicTests/MagicTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MagicTests.swift 3 | // MagicTests 4 | // 5 | // Created by Kishikawa Katsumi on 2018/12/23. 6 | // Copyright © 2018 Kishikawa Katsumi. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Magic 11 | 12 | class MagicTests: XCTestCase { 13 | func testDescription() { 14 | do { 15 | guard let filePath = Bundle(for: MagicTests.self).url(forResource: "Info", withExtension: "plist") else { 16 | fatalError() 17 | } 18 | XCTAssertEqual(try! Magic.shared.file(filePath), "Apple binary property list") 19 | } 20 | } 21 | 22 | func testMimeType() { 23 | do { 24 | guard let filePath = Bundle(for: MagicTests.self).url(forResource: "Info", withExtension: "plist") else { 25 | fatalError() 26 | } 27 | XCTAssertEqual(try! Magic.shared.file(filePath, flags: .mime), "application/octet-stream; charset=binary") 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://app.bitrise.io/app/b4717764acae567c/status.svg?token=X3pkDXIRd3cRfUST2aHDyA)](https://app.bitrise.io/app/b4717764acae567c) [![CocoaPods](https://img.shields.io/cocoapods/v/swift-magic.svg?style=flat)](https://cocoapods.org/pods/swift-magic) [![Carthage](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage) 2 | 3 | # swift-magic 4 | A Swift wrapper for libmagic 5 | 6 | swift-magic is a Swift interface to the libmagic file type 7 | identification library. libmagic identifies file types by checking 8 | their headers according to a predefined list of file types. This 9 | functionality is exposed to the command line by the Unix command 10 | `file`. 11 | 12 | ## Usage 13 | 14 | ```swift 15 | import Magic 16 | 17 | let description = try Magic.shared.file(path) 18 | ``` 19 | 20 | ## Requirements 21 | swift-magic is written in Swift 4.2. Compatible with iOS 8.0+ 22 | 23 | ## Installation 24 | 25 | ### CocoaPods 26 | swift-magic is available through [CocoaPods](https://cocoapods.org). To install 27 | it, simply add the following line to your Podfile: 28 | 29 | ```ruby 30 | pod 'swift-magic' 31 | ``` 32 | 33 | ### Carthage 34 | For [Carthage](https://github.com/Carthage/Carthage), add the following to your `Cartfile`: 35 | 36 | ```ogdl 37 | github "kishikawakatsumi/swift-magic" 38 | ``` 39 | 40 | ## Author 41 | Kishikawa Katsumi, kishikawakatsumi@mac.com 42 | 43 | ## License 44 | swift-magic is available under the BSD license. See the LICENSE file for more info. 45 | -------------------------------------------------------------------------------- /Scripts/build_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -ex 3 | 4 | SCRIPT_DIR=`dirname "$0"` 5 | 6 | TDIR=`mktemp -d` 7 | trap "{ cd - ; rm -rf $TDIR; exit 255; }" SIGINT 8 | 9 | cd $TDIR 10 | 11 | git clone https://github.com/file/file src 12 | 13 | CURRENTPATH=`pwd` 14 | 15 | TARGETDIR_MACOSX="$CURRENTPATH/.build/macosx" 16 | mkdir -p "$TARGETDIR_MACOSX" 17 | TARGETDIR_IPHONEOS="$CURRENTPATH/.build/iphoneos" 18 | mkdir -p "$TARGETDIR_IPHONEOS" 19 | TARGETDIR_IPHONESIMULATOR="$CURRENTPATH/.build/iphonesimulator" 20 | mkdir -p "$TARGETDIR_IPHONESIMULATOR" 21 | 22 | (cd src && autoreconf -if) 23 | (cd src && ./configure --prefix="$TARGETDIR_MACOSX" --disable-shared --enable-static CFLAGS="-mmacosx-version-min=10.9" CXXFLAGS="-mmacosx-version-min=10.9" && make install) 24 | (cd src && ./configure --prefix="$TARGETDIR_IPHONEOS" --disable-shared --enable-static --host=arm-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode -mios-version-min=8.0" && make install) 25 | (cd src && ./configure --prefix="$TARGETDIR_IPHONESIMULATOR" --disable-shared --enable-static --host=x86_64-apple-darwin CC=`xcrun -find clang` CFLAGS="-O3 -arch i386 -arch x86_64 -isysroot `xcrun -sdk iphonesimulator --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" CXX=`xcrun -find clang++` CXXFLAGS="-O3 -arch i386 -arch x86_64 -isysroot `xcrun -sdk iphoneos --show-sdk-path` -fembed-bitcode-marker -mios-simulator-version-min=8.0" && make install) 26 | 27 | cd - 28 | 29 | mkdir -p "$SCRIPT_DIR/../Vendor/magic/include" 30 | mkdir -p "$SCRIPT_DIR/../Vendor/magic/lib" 31 | mkdir -p "$SCRIPT_DIR/../Vendor/magic/share" 32 | 33 | cp -rf "$TARGETDIR_MACOSX/include" "$SCRIPT_DIR/../Vendor/magic/" 34 | cp -rf "$TARGETDIR_MACOSX/share/misc" "$SCRIPT_DIR/../Vendor/magic/share" 35 | 36 | xcrun lipo -create "$TARGETDIR_IPHONEOS/lib/libmagic.a" \ 37 | "$TARGETDIR_IPHONESIMULATOR/lib/libmagic.a" \ 38 | -o "$SCRIPT_DIR/../Vendor/magic/lib/libmagic.a" 39 | 40 | rm -rf $TDIR 41 | -------------------------------------------------------------------------------- /Vendor/magic/include/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kishikawakatsumi/swift-magic/3ab9969c2037a3768613c9b5314b3c69da8361a9/Vendor/magic/include/.gitkeep -------------------------------------------------------------------------------- /Vendor/magic/include/magic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Christos Zoulas 2003. 3 | * All Rights Reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice immediately at the beginning of the file, without modification, 10 | * this list of conditions, and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | */ 27 | #ifndef _MAGIC_H 28 | #define _MAGIC_H 29 | 30 | #include 31 | 32 | #define MAGIC_NONE 0x0000000 /* No flags */ 33 | #define MAGIC_DEBUG 0x0000001 /* Turn on debugging */ 34 | #define MAGIC_SYMLINK 0x0000002 /* Follow symlinks */ 35 | #define MAGIC_COMPRESS 0x0000004 /* Check inside compressed files */ 36 | #define MAGIC_DEVICES 0x0000008 /* Look at the contents of devices */ 37 | #define MAGIC_MIME_TYPE 0x0000010 /* Return the MIME type */ 38 | #define MAGIC_CONTINUE 0x0000020 /* Return all matches */ 39 | #define MAGIC_CHECK 0x0000040 /* Print warnings to stderr */ 40 | #define MAGIC_PRESERVE_ATIME 0x0000080 /* Restore access time on exit */ 41 | #define MAGIC_RAW 0x0000100 /* Don't convert unprintable chars */ 42 | #define MAGIC_ERROR 0x0000200 /* Handle ENOENT etc as real errors */ 43 | #define MAGIC_MIME_ENCODING 0x0000400 /* Return the MIME encoding */ 44 | #define MAGIC_MIME (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING) 45 | #define MAGIC_APPLE 0x0000800 /* Return the Apple creator/type */ 46 | #define MAGIC_EXTENSION 0x1000000 /* Return a /-separated list of 47 | * extensions */ 48 | #define MAGIC_COMPRESS_TRANSP 0x2000000 /* Check inside compressed files 49 | * but not report compression */ 50 | #define MAGIC_NODESC (MAGIC_EXTENSION|MAGIC_MIME|MAGIC_APPLE) 51 | 52 | #define MAGIC_NO_CHECK_COMPRESS 0x0001000 /* Don't check for compressed files */ 53 | #define MAGIC_NO_CHECK_TAR 0x0002000 /* Don't check for tar files */ 54 | #define MAGIC_NO_CHECK_SOFT 0x0004000 /* Don't check magic entries */ 55 | #define MAGIC_NO_CHECK_APPTYPE 0x0008000 /* Don't check application type */ 56 | #define MAGIC_NO_CHECK_ELF 0x0010000 /* Don't check for elf details */ 57 | #define MAGIC_NO_CHECK_TEXT 0x0020000 /* Don't check for text files */ 58 | #define MAGIC_NO_CHECK_CDF 0x0040000 /* Don't check for cdf files */ 59 | #define MAGIC_NO_CHECK_TOKENS 0x0100000 /* Don't check tokens */ 60 | #define MAGIC_NO_CHECK_ENCODING 0x0200000 /* Don't check text encodings */ 61 | #define MAGIC_NO_CHECK_JSON 0x0400000 /* Don't check for JSON files */ 62 | 63 | /* No built-in tests; only consult the magic file */ 64 | #define MAGIC_NO_CHECK_BUILTIN ( \ 65 | MAGIC_NO_CHECK_COMPRESS | \ 66 | MAGIC_NO_CHECK_TAR | \ 67 | /* MAGIC_NO_CHECK_SOFT | */ \ 68 | MAGIC_NO_CHECK_APPTYPE | \ 69 | MAGIC_NO_CHECK_ELF | \ 70 | MAGIC_NO_CHECK_TEXT | \ 71 | MAGIC_NO_CHECK_CDF | \ 72 | MAGIC_NO_CHECK_TOKENS | \ 73 | MAGIC_NO_CHECK_ENCODING | \ 74 | MAGIC_NO_CHECK_JSON | \ 75 | 0 \ 76 | ) 77 | 78 | #define MAGIC_SNPRINTB "\177\020\ 79 | b\0debug\0\ 80 | b\1symlink\0\ 81 | b\2compress\0\ 82 | b\3devices\0\ 83 | b\4mime_type\0\ 84 | b\5continue\0\ 85 | b\6check\0\ 86 | b\7preserve_atime\0\ 87 | b\10raw\0\ 88 | b\11error\0\ 89 | b\12mime_encoding\0\ 90 | b\13apple\0\ 91 | b\14no_check_compress\0\ 92 | b\15no_check_tar\0\ 93 | b\16no_check_soft\0\ 94 | b\17no_check_sapptype\0\ 95 | b\20no_check_elf\0\ 96 | b\21no_check_text\0\ 97 | b\22no_check_cdf\0\ 98 | b\23no_check_reserved0\0\ 99 | b\24no_check_tokens\0\ 100 | b\25no_check_encoding\0\ 101 | b\26no_check_json\0\ 102 | b\27no_check_reserved2\0\ 103 | b\30extension\0\ 104 | b\31transp_compression\0\ 105 | " 106 | 107 | /* Defined for backwards compatibility (renamed) */ 108 | #define MAGIC_NO_CHECK_ASCII MAGIC_NO_CHECK_TEXT 109 | 110 | /* Defined for backwards compatibility; do nothing */ 111 | #define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */ 112 | #define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */ 113 | 114 | #define MAGIC_VERSION 535 /* This implementation */ 115 | 116 | 117 | #ifdef __cplusplus 118 | extern "C" { 119 | #endif 120 | 121 | typedef struct magic_set *magic_t; 122 | magic_t magic_open(int); 123 | void magic_close(magic_t); 124 | 125 | const char *magic_getpath(const char *, int); 126 | const char *magic_file(magic_t, const char *); 127 | const char *magic_descriptor(magic_t, int); 128 | const char *magic_buffer(magic_t, const void *, size_t); 129 | 130 | const char *magic_error(magic_t); 131 | int magic_getflags(magic_t); 132 | int magic_setflags(magic_t, int); 133 | 134 | int magic_version(void); 135 | int magic_load(magic_t, const char *); 136 | int magic_load_buffers(magic_t, void **, size_t *, size_t); 137 | 138 | int magic_compile(magic_t, const char *); 139 | int magic_check(magic_t, const char *); 140 | int magic_list(magic_t, const char *); 141 | int magic_errno(magic_t); 142 | 143 | #define MAGIC_PARAM_INDIR_MAX 0 144 | #define MAGIC_PARAM_NAME_MAX 1 145 | #define MAGIC_PARAM_ELF_PHNUM_MAX 2 146 | #define MAGIC_PARAM_ELF_SHNUM_MAX 3 147 | #define MAGIC_PARAM_ELF_NOTES_MAX 4 148 | #define MAGIC_PARAM_REGEX_MAX 5 149 | #define MAGIC_PARAM_BYTES_MAX 6 150 | 151 | int magic_setparam(magic_t, int, const void *); 152 | int magic_getparam(magic_t, int, void *); 153 | 154 | #ifdef __cplusplus 155 | }; 156 | #endif 157 | 158 | #endif /* _MAGIC_H */ 159 | -------------------------------------------------------------------------------- /Vendor/magic/lib/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kishikawakatsumi/swift-magic/3ab9969c2037a3768613c9b5314b3c69da8361a9/Vendor/magic/lib/.gitkeep -------------------------------------------------------------------------------- /Vendor/magic/lib/libmagic.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kishikawakatsumi/swift-magic/3ab9969c2037a3768613c9b5314b3c69da8361a9/Vendor/magic/lib/libmagic.a -------------------------------------------------------------------------------- /Vendor/magic/module.modulemap: -------------------------------------------------------------------------------- 1 | module cmagic { 2 | header "include/magic.h" 3 | link "magic" 4 | link "z" 5 | } 6 | -------------------------------------------------------------------------------- /Vendor/magic/share/misc/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kishikawakatsumi/swift-magic/3ab9969c2037a3768613c9b5314b3c69da8361a9/Vendor/magic/share/misc/.gitkeep -------------------------------------------------------------------------------- /Vendor/magic/share/misc/magic.mgc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kishikawakatsumi/swift-magic/3ab9969c2037a3768613c9b5314b3c69da8361a9/Vendor/magic/share/misc/magic.mgc -------------------------------------------------------------------------------- /swift-magic.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = 'swift-magic' 3 | spec.version = '0.5.5' 4 | spec.summary = 'A Swift wrapper for libmagic' 5 | spec.description = <<-DESC 6 | swift-magic is a Swift interface to the libmagic file type identification library. libmagic identifies file types by checking their headers according to a predefined list of file types. This functionality is exposed to the command line by the Unix command `file`. 7 | ``` 8 | DESC 9 | spec.homepage = 'https://github.com/kishikawakatsumi/swift-magic' 10 | spec.license = { :type => 'BSD', :file => 'LICENSE' } 11 | spec.author = { 'kishikawa katsumi' => 'kishikawakatsumi@mac.com' } 12 | 13 | spec.requires_arc = true 14 | spec.source = { git: 'https://github.com/kishikawakatsumi/swift-magic.git', tag: "v#{spec.version}" } 15 | spec.source_files = 'Magic/**/*.{h,swift}' 16 | spec.resources = 'Vendor/magic/share/misc/magic.mgc' 17 | spec.module_name = 'Magic' 18 | spec.ios.deployment_target = '8.0' 19 | spec.swift_version = '4.2' 20 | 21 | spec.pod_target_xcconfig = { 'APPLICATION_EXTENSION_API_ONLY' => 'YES', 22 | 'SWIFT_INCLUDE_PATHS' => '${PODS_ROOT}/swift-magic/Vendor', 23 | 'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/swift-magic/Vendor/magic/include"', 24 | 'LIBRARY_SEARCH_PATHS' => '"${PODS_ROOT}/swift-magic/Vendor/magic/lib"' } 25 | spec.preserve_paths = ['Vendor'] 26 | end 27 | --------------------------------------------------------------------------------