Compare commits
61 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
1bf0af80bb | |
![]() |
984de192ea | |
![]() |
5968a3aff2 | |
![]() |
e0cfd40496 | |
![]() |
6ac7090646 | |
![]() |
2bf41a2cd5 | |
![]() |
65c5237602 | |
![]() |
450ba6cef5 | |
![]() |
15ecf990d0 | |
![]() |
66df0c6376 | |
![]() |
0f36dd90d0 | |
![]() |
193e3e01a5 | |
![]() |
e5cc25a31a | |
![]() |
d374bc9186 | |
![]() |
ac627c01d7 | |
![]() |
2638053ed1 | |
![]() |
a66b465574 | |
![]() |
76c1b21e98 | |
![]() |
eb14b3114c | |
![]() |
ce89810fdd | |
![]() |
29a762c572 | |
![]() |
b5fb608ce5 | |
![]() |
3e2df60c27 | |
![]() |
590a9dbd87 | |
![]() |
4e815c3049 | |
![]() |
b2b4d5e711 | |
![]() |
1a2aaef303 | |
![]() |
318af31c27 | |
![]() |
a5548b4780 | |
![]() |
8acf4c56ba | |
![]() |
9e50381130 | |
![]() |
775834939e | |
![]() |
ed86be8b0f | |
![]() |
e23fa26475 | |
![]() |
984b7ffdca | |
![]() |
536b4f9968 | |
![]() |
3361886483 | |
![]() |
d42f9549b2 | |
![]() |
acece91dd9 | |
![]() |
ea50b8afad | |
![]() |
0d06741ce8 | |
![]() |
a87accf55f | |
![]() |
eb97d7afe6 | |
![]() |
a0e298ec1d | |
![]() |
22a661a1b7 | |
![]() |
7847fbe03c | |
![]() |
9bae09258f | |
![]() |
b2702ed637 | |
![]() |
42aa83bbad | |
![]() |
9fd21a6185 | |
![]() |
c863a3db5e | |
![]() |
3caaa48825 | |
![]() |
d02cd01cae | |
![]() |
5e7472358e | |
![]() |
a3bcbd86e7 | |
![]() |
b0e7984f2b | |
![]() |
23545eb6b2 | |
![]() |
a6253d6446 | |
![]() |
0c30d19662 | |
![]() |
ceab4f1cb1 | |
![]() |
d19d16f461 |
|
@ -50,7 +50,7 @@ playground.xcworkspace
|
|||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
Carthage/Checkouts
|
||||
|
||||
Carthage/Build
|
||||
|
||||
|
@ -68,3 +68,4 @@ fastlane/test_output
|
|||
Fileable.framework.zip
|
||||
|
||||
MEMO.md
|
||||
.DS_Store
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
image: kylef/swiftenv
|
||||
|
||||
before_script:
|
||||
- swiftenv install https://swift.org/builds/swift-3.1-release/ubuntu1604/swift-3.1-RELEASE/swift-3.1-RELEASE-ubuntu16.04.tar.gz
|
||||
|
||||
test:
|
||||
script:
|
||||
- swift build
|
||||
tags:
|
||||
- vapor
|
|
@ -1 +1 @@
|
|||
4.2
|
||||
5.1.3
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
osx_image: xcode10
|
||||
osx_image: xcode12.5
|
||||
language: objective-c
|
||||
xcode_project: Fileable.xcodeproj
|
||||
xcode_scheme: Fileable
|
||||
xcode_destination: platform=iOS Simulator,OS=12.0,name=iPhone XS
|
||||
xcode_scheme: Fileable-Package
|
||||
xcode_destination: platform=iOS Simulator,OS=14.5,name=iPhone 11
|
||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,3 +1,19 @@
|
|||
## Version 1.2.1
|
||||
|
||||
- Fix internal inaccessible level
|
||||
|
||||
## Version 1.2
|
||||
|
||||
- Implement get bundle file path method
|
||||
|
||||
- Support both String and URL type as a path param
|
||||
|
||||
- Separate platform specific method as a service
|
||||
|
||||
- Support making multiple directory at once
|
||||
|
||||
- Add path absolute or relative detector
|
||||
|
||||
## Version 1.1
|
||||
|
||||
- Fix building scheme failure
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'Fileable'
|
||||
s.version = '1.0.9'
|
||||
s.version = '1.1'
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.summary = 'Unix command like file management library for Swift.'
|
||||
s.description = <<-DESC
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,8 +39,6 @@
|
|||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
|
@ -52,17 +50,6 @@
|
|||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Fileable::Fileable"
|
||||
BuildableName = "Fileable.framework"
|
||||
BlueprintName = "Fileable"
|
||||
ReferencedContainer = "container:Fileable.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
|
@ -1,81 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "9999"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Fileable::Fileable"
|
||||
BuildableName = "Fileable.framework"
|
||||
BlueprintName = "Fileable"
|
||||
ReferencedContainer = "container:Fileable.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Fileable::FileableTests"
|
||||
BuildableName = "FileableTests.xctest"
|
||||
BlueprintName = "FileableTests"
|
||||
ReferencedContainer = "container:Fileable.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Fileable::Fileable"
|
||||
BuildableName = "Fileable.framework"
|
||||
BlueprintName = "Fileable"
|
||||
ReferencedContainer = "container:Fileable.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017-2018 Shota Shimazu
|
||||
Copyright (c) 2017-2019 Shota Shimazu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// swift-tools-version:4.0
|
||||
// swift-tools-version:5.0
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
|
10
README.md
10
README.md
|
@ -1,11 +1,11 @@
|
|||

|
||||
|
||||
[](https://travis-ci.org/shotastage/Fileable.swift)
|
||||
[](https://travis-ci.com/shotastage/Fileable.swift)
|
||||
[](https://github.com/shotasatge/Fileable)
|
||||
[](http://cocoapods.org/pods/Fileable)
|
||||

|
||||

|
||||

|
||||

|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fshotastage%2FFileable.swift?ref=badge_shield)
|
||||
|
||||
|
||||
Fileable is file utilities for Swift.
|
||||
|
@ -48,6 +48,10 @@ github "shotastage/Fileable"
|
|||
|
||||
|
||||
# License
|
||||
|
||||
Fileable is licensed under the `MIT`.
|
||||
You can use this library free of charge. Please include copyright notie in your program.
|
||||
See [LICENSE](./LICENSE) for detail.
|
||||
|
||||
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fshotastage%2FFileable.swift?ref=badge_large)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2017/10/25.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
@ -33,6 +33,11 @@ public enum FileableError: Error {
|
|||
/// Previous
|
||||
case AleardyExists
|
||||
|
||||
/// Zip
|
||||
case InvalidZipFile
|
||||
case ZipCompressFailure
|
||||
case ZipExtractFailure
|
||||
|
||||
/// Default
|
||||
case Unkown(String)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on Oct 25, 2017.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
@ -13,21 +13,45 @@ open class Path {
|
|||
// Path
|
||||
var path: String
|
||||
|
||||
// Separator
|
||||
public var separator: String = "/"
|
||||
|
||||
// Foundational File Manager
|
||||
static var fm = FileManager.default
|
||||
|
||||
// Services
|
||||
#if os(iOS) || os(watchOS) || os(tvOS)
|
||||
public static let ios = FileableIOS.shared
|
||||
#endif
|
||||
|
||||
#if os(Linux)
|
||||
public static let linux = FileableLinux.shared
|
||||
#endif
|
||||
|
||||
|
||||
// Initializers
|
||||
public init() {
|
||||
public required init() {
|
||||
self.path = Path.pwd
|
||||
}
|
||||
|
||||
public init(_ path: String) {
|
||||
if path == "~" {
|
||||
self.path = Path.home
|
||||
public init<T>(_ path: T) {
|
||||
|
||||
let castedPath: String
|
||||
|
||||
/// Compatible for both String and URL type
|
||||
if let pathURL: URL = path as? URL {
|
||||
castedPath = pathURL.path
|
||||
} else {
|
||||
self.path = path
|
||||
castedPath = path as! String
|
||||
}
|
||||
|
||||
|
||||
self.path = castedPath
|
||||
|
||||
if castedPath == "~" {
|
||||
if let range = castedPath.range(of: "~") {
|
||||
self.path.replaceSubrange(range, with: Path.home)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
//
|
||||
// Linux+Fileable.swift
|
||||
// FHS.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2017/10/25.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
#if os(Linux)
|
||||
open class FileableLinux {
|
||||
|
||||
public static let shared = FileableLinux()
|
||||
|
||||
|
||||
private init() { }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public enum UnixFS {
|
||||
|
||||
case root
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// Network.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2019/01/13.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
#if DEBUG
|
||||
open class Downloader {
|
||||
|
||||
public static let shared = Downloader()
|
||||
|
||||
private init() { }
|
||||
|
||||
func save(to: String) {
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -3,13 +3,14 @@
|
|||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2017/10/25.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Path {
|
||||
|
||||
// TODO: Implement cd clousure like Python with statement
|
||||
public static func cd(_ path: String) throws {
|
||||
if !Path.fm.changeCurrentDirectoryPath(path) {
|
||||
if !Path.fm.fileExists(atPath: path) {
|
||||
|
@ -19,9 +20,13 @@ extension Path {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func mkdir(_ path: String) throws {
|
||||
try Path.fm.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
|
||||
|
||||
public static func mkdir(_ paths: String..., ignoreError: Bool = true) throws {
|
||||
|
||||
for path in paths {
|
||||
try Path.fm.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public func rm() throws {
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// Permissions.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2018/12/04.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public enum FileablePermissions {
|
||||
case Readable
|
||||
case Writeable
|
||||
case Executable
|
||||
case ReadOnly
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2017/10/25.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
@ -105,3 +105,18 @@ extension Path {
|
|||
return String(fileName.split(separator: ".").last!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Path type
|
||||
extension Path {
|
||||
|
||||
/// Return whether path is absolute
|
||||
public var isAbsolute: Bool {
|
||||
return self.path.hasPrefix("/")
|
||||
}
|
||||
|
||||
/// Return whether path is relative
|
||||
public var isRelative: Bool {
|
||||
return !isAbsolute
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// Utilities.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2018/12/09.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
extension Path {
|
||||
|
||||
//
|
||||
// URL Converter
|
||||
//
|
||||
public static func toURL(string: String) -> URL {
|
||||
return URL(fileURLWithPath: string)
|
||||
}
|
||||
|
||||
public static func toString(fileURL: URL) throws -> String {
|
||||
|
||||
let stringURL: String
|
||||
|
||||
do {
|
||||
try stringURL = String(contentsOf: fileURL)
|
||||
}
|
||||
catch {
|
||||
throw FileableError.TypeConvertionError
|
||||
}
|
||||
|
||||
return stringURL
|
||||
}
|
||||
|
||||
|
||||
/// Change default slash separator
|
||||
func changeDefaultSeparator(for newSeparator: String) {
|
||||
self.separator = newSeparator
|
||||
}
|
||||
|
||||
|
||||
/// Change defualt file manager instance
|
||||
func changeFileManagerBackend(new fmInstance: FileManager) {
|
||||
Path.fm = fmInstance
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
//
|
||||
// ZipArchive.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2018/12/09.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
#if os(Linux)
|
||||
import MiniZip
|
||||
#endif
|
||||
|
||||
/*
|
||||
public enum ZipCompressionLevel {
|
||||
case NoCompression
|
||||
case BestSpeed
|
||||
case Default
|
||||
case BestCompression
|
||||
|
||||
|
||||
|
||||
var minizipLevel: Int32 {
|
||||
switch self {
|
||||
case .NoCompression:
|
||||
return Z_NO_COMPRESSION
|
||||
|
||||
case .BestSpeed:
|
||||
return Z_BEST_SPEED
|
||||
|
||||
case .Default:
|
||||
return Z_DEFAULT_COMPRESSION
|
||||
|
||||
case .BestCompression:
|
||||
return Z_BEST_COMPRESSION
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class FileableZipArchiver {
|
||||
|
||||
// TODO: Complete implementing unzip method
|
||||
func unzipFile(file: String, password: String?) throws {
|
||||
|
||||
// Unzip set up
|
||||
var ret: Int32 = 0
|
||||
var crc_ret: Int32 = 0
|
||||
let bufferSize: UInt32 = 4096
|
||||
var buffer = Array<CUnsignedChar>(repeating: 0, count: Int(bufferSize))
|
||||
|
||||
|
||||
/// Open Zip file
|
||||
let unzipTarget = unzOpen64(file)
|
||||
|
||||
/// Procedure
|
||||
if unzGoToFirstFile(unzipTarget) != UNZ_OK {
|
||||
throw FileableError.ZipExtractFailure
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// Close Zip file
|
||||
defer {
|
||||
unzClose(unzipTarget)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: Complete implementing zip method
|
||||
func zipFile(file: String, password: String?, level: ZipCompressionLevel) throws {
|
||||
throw FileableError.ZipCompressFailure
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
extension Path {
|
||||
|
||||
// TODO: Implement unzip
|
||||
func unzip(password: String? = nil) throws {
|
||||
|
||||
guard !Path(self.path).isDir else {
|
||||
throw FileableError.InvalidZipFile
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func compress(password: String? = nil) throws {
|
||||
// TODO: Implement zipping
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -1,83 +0,0 @@
|
|||
//
|
||||
// iOS+Fileable.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2017/10/25.
|
||||
// Copyright © 2017-2018 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
#if os(iOS) || os(watchOS) || os(tvOS)
|
||||
|
||||
extension Path {
|
||||
|
||||
///
|
||||
/// Deprecated methods
|
||||
///
|
||||
@available(*, unavailable, renamed: "iOSFileSystem.document.path")
|
||||
static func appDocument() -> String {
|
||||
fatalError("appDocument is deprecated!")
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "iOSFileSystem.cache.path")
|
||||
static func appCache() -> String {
|
||||
fatalError("appCache is deprecated!")
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// URL Converter
|
||||
//
|
||||
public static func toURL(string: String) -> URL {
|
||||
return URL(fileURLWithPath: string)
|
||||
}
|
||||
|
||||
public static func toString(fileURL: URL) throws -> String {
|
||||
|
||||
let stringURL: String
|
||||
|
||||
do {
|
||||
try stringURL = String(contentsOf: fileURL)
|
||||
}
|
||||
catch {
|
||||
throw FileableError.TypeConvertionError
|
||||
}
|
||||
|
||||
return stringURL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// iOSDir enum is list of iOS application directories
|
||||
public enum IOSDir {
|
||||
|
||||
/// .document returns iOS Documents directory
|
||||
case document
|
||||
case inbox
|
||||
case library
|
||||
case cache
|
||||
case tmp
|
||||
|
||||
|
||||
/// path propaty returns directory path as String type
|
||||
var path: String! {
|
||||
switch self {
|
||||
|
||||
case .document:
|
||||
return Path.fm.urls(for: .documentDirectory, in: .userDomainMask)[0].path
|
||||
case .inbox:
|
||||
return Path.fm.urls(for: .documentDirectory, in: .userDomainMask)[0].path + "inbox/"
|
||||
case .library:
|
||||
return Path.fm.urls(for: .libraryDirectory, in: .userDomainMask)[0].path
|
||||
case .cache:
|
||||
return Path.fm.urls(for: .cachesDirectory, in: .userDomainMask)[0].path
|
||||
case .tmp:
|
||||
return Path.fm.temporaryDirectory.path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// iOSFileable.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2018/12/09.
|
||||
// Copyright © 2017-2020 Shota Shimazu. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
|
||||
#if os(iOS) || os(watchOS) || os(tvOS)
|
||||
|
||||
open class FileableIOS {
|
||||
|
||||
public static let shared = FileableIOS()
|
||||
|
||||
private init() { }
|
||||
|
||||
public func getBundle(file: String) -> String? {
|
||||
|
||||
let path = Bundle.main.path(forResource: file.components(separatedBy: ".")[0] , ofType: file.components(separatedBy: ".")[1])
|
||||
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum IOSDirs {
|
||||
|
||||
/// .document returns iOS Documents directory
|
||||
case document
|
||||
case inbox
|
||||
case library
|
||||
case cache
|
||||
case tmp
|
||||
|
||||
|
||||
/// path propaty returns directory path as String type
|
||||
@available(iOS 10.0, *)
|
||||
var path: String! {
|
||||
switch self {
|
||||
|
||||
case .document:
|
||||
return Path.fm.urls(for: .documentDirectory, in: .userDomainMask)[0].path
|
||||
case .inbox:
|
||||
return Path.fm.urls(for: .documentDirectory, in: .userDomainMask)[0].path + "inbox/"
|
||||
case .library:
|
||||
return Path.fm.urls(for: .libraryDirectory, in: .userDomainMask)[0].path
|
||||
case .cache:
|
||||
return Path.fm.urls(for: .cachesDirectory, in: .userDomainMask)[0].path
|
||||
case .tmp:
|
||||
return Path.fm.temporaryDirectory.path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
33
TODO.md
33
TODO.md
|
@ -1,10 +1,37 @@
|
|||
# Version 1.3
|
||||
|
||||
- [ ] Implement Zip manager
|
||||
|
||||
- [ ] Implement downloader
|
||||
|
||||
- [ ] Implement cache system
|
||||
|
||||
- [ ] Implement Document Directory Manager
|
||||
|
||||
- [ ] Implement change mode
|
||||
|
||||
## Version 1.2 **[Current]**
|
||||
|
||||
- [x] Implement get bundle file path method
|
||||
|
||||
- [x] Support both String and URL type as a path param
|
||||
|
||||
- [x] Separate platform specific method as a service
|
||||
|
||||
- [x] Support making multiple directory at once
|
||||
|
||||
- [x] Add path absolute or relative detector
|
||||
|
||||
|
||||
|
||||
|
||||
## Version 1.0.9
|
||||
|
||||
- Implement Chmod
|
||||
- [ ] Implement Chmod
|
||||
|
||||
- iOS Directory
|
||||
- [x] iOS Directory
|
||||
|
||||
|
||||
## Version 1.0.8
|
||||
|
||||
- Implement List Dir
|
||||
- [x] Implement List Dir
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// PathTypeCasting.swift
|
||||
// Fileable
|
||||
//
|
||||
// Created by Shota Shimazu on 2018/12/10.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import Fileable
|
||||
|
||||
|
||||
class PathTypeCastingTest: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
func testStringPathType() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
let path: String = "~"
|
||||
|
||||
let fm = FileManager.default
|
||||
|
||||
|
||||
XCTAssertTrue(Path(path).path == fm.currentDirectoryPath)
|
||||
}
|
||||
|
||||
|
||||
func testURLPathType() {
|
||||
|
||||
let fm = FileManager.default
|
||||
|
||||
let path: URL = URL(fileURLWithPath: fm.currentDirectoryPath, isDirectory: true)
|
||||
|
||||
XCTAssertTrue(Path(path).path == fm.currentDirectoryPath)
|
||||
}
|
||||
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
|
||||
self.measure { }
|
||||
}
|
||||
}
|
|
@ -23,13 +23,32 @@ class IOSDirsTest: XCTestCase {
|
|||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
|
||||
//let documentDirectory: String = IOSDirs.document.path
|
||||
//let libraryDirectory: String = IOSDirs.library.path
|
||||
let documentDirectory: String = IOSDirs.document.path
|
||||
let inboxDirectory: String = IOSDirs.inbox.path
|
||||
let libraryDirectory: String = IOSDirs.library.path
|
||||
let cacheDirectory: String = IOSDirs.cache.path
|
||||
let tmpDirectory: String = IOSDirs.tmp.path
|
||||
|
||||
NSLog("LOG: ")
|
||||
// NSLog(documentDirectory)
|
||||
// NSLog(libraryDirectory)
|
||||
// XCTAssertEqual(current, moved)
|
||||
|
||||
NSLog("LOG: \(documentDirectory)")
|
||||
NSLog("LOG: \(inboxDirectory)")
|
||||
NSLog("LOG: \(libraryDirectory)")
|
||||
NSLog("LOG: \(cacheDirectory)")
|
||||
NSLog("LOG: \(tmpDirectory)")
|
||||
|
||||
|
||||
XCTAssertTrue(documentDirectory.contains("Documents"))
|
||||
XCTAssertTrue(inboxDirectory.contains("Documentsinbox"))
|
||||
XCTAssertTrue(libraryDirectory.contains("Library"))
|
||||
XCTAssertTrue(cacheDirectory.contains("Library/Caches"))
|
||||
XCTAssertTrue(tmpDirectory.contains("tmp"))
|
||||
}
|
||||
|
||||
|
||||
func testGetBundleFile() {
|
||||
let path = Path.ios.getBundle(file: "unlocated.txt")
|
||||
|
||||
XCTAssertNil(path)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue