Compare commits

..

No commits in common. "main" and "1.1" have entirely different histories.
main ... 1.1

26 changed files with 728 additions and 1204 deletions

3
.gitignore vendored
View File

@ -50,7 +50,7 @@ playground.xcworkspace
# Carthage # Carthage
# #
# Add this line if you want to avoid checking in source code from Carthage dependencies. # Add this line if you want to avoid checking in source code from Carthage dependencies.
Carthage/Checkouts # Carthage/Checkouts
Carthage/Build Carthage/Build
@ -68,4 +68,3 @@ fastlane/test_output
Fileable.framework.zip Fileable.framework.zip
MEMO.md MEMO.md
.DS_Store

10
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,10 @@
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

View File

@ -1 +1 @@
5.1.3 4.2

View File

@ -1,5 +1,5 @@
osx_image: xcode12.5 osx_image: xcode10
language: objective-c language: objective-c
xcode_project: Fileable.xcodeproj xcode_project: Fileable.xcodeproj
xcode_scheme: Fileable-Package xcode_scheme: Fileable
xcode_destination: platform=iOS Simulator,OS=14.5,name=iPhone 11 xcode_destination: platform=iOS Simulator,OS=12.0,name=iPhone XS

View File

@ -1,19 +1,3 @@
## 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 ## Version 1.1
- Fix building scheme failure - Fix building scheme failure

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Fileable' s.name = 'Fileable'
s.version = '1.1' s.version = '1.0.9'
s.license = { :type => 'MIT', :file => 'LICENSE' } s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'Unix command like file management library for Swift.' s.summary = 'Unix command like file management library for Swift.'
s.description = <<-DESC s.description = <<-DESC

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,8 @@
</BuildableReference> </BuildableReference>
</TestableReference> </TestableReference>
</Testables> </Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Debug"
@ -50,6 +52,17 @@
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal" debugServiceExtension = "internal"
allowLocationSimulation = "YES"> allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Fileable::Fileable"
BuildableName = "Fileable.framework"
BlueprintName = "Fileable"
ReferencedContainer = "container:Fileable.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release" buildConfiguration = "Release"

View File

@ -0,0 +1,81 @@
<?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>

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2017-2019 Shota Shimazu Copyright (c) 2017-2018 Shota Shimazu
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,4 +1,4 @@
// swift-tools-version:5.0 // swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package. // The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription import PackageDescription

View File

@ -1,11 +1,11 @@
![Fileable](./Documentation/filekit_readme.png) ![Fileable](./Documentation/filekit_readme.png)
[![Build Status](https://travis-ci.com/shotastage/Fileable.swift.svg?branch=main)](https://travis-ci.com/shotastage/Fileable.swift) [![Build Status](https://travis-ci.org/shotastage/Fileable.swift.svg?branch=master)](https://travis-ci.org/shotastage/Fileable.swift)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/shotasatge/Fileable) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/shotasatge/Fileable)
[![Version](https://img.shields.io/cocoapods/v/Fileable.svg?style=flat)](http://cocoapods.org/pods/Fileable) [![Version](https://img.shields.io/cocoapods/v/Fileable.svg?style=flat)](http://cocoapods.org/pods/Fileable)
![iOS 10+](https://img.shields.io/badge/iOS-10%2B-blue.svg?style=flat) ![iOS 10+](https://img.shields.io/badge/iOS-10%2B-blue.svg?style=flat)
![Swift 5](https://img.shields.io/badge/Swift-5-orange.svg?style=flat) ![Linux supported](https://img.shields.io/badge/Linux-supported-5D9CEC.svg?style=flat)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fshotastage%2FFileable.swift.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fshotastage%2FFileable.swift?ref=badge_shield) ![Swift 4](https://img.shields.io/badge/Swift-4-orange.svg?style=flat)
Fileable is file utilities for Swift. Fileable is file utilities for Swift.
@ -48,10 +48,6 @@ github "shotastage/Fileable"
# License # License
Fileable is licensed under the `MIT`. Fileable is licensed under the `MIT`.
You can use this library free of charge. Please include copyright notie in your program. You can use this library free of charge. Please include copyright notie in your program.
See [LICENSE](./LICENSE) for detail. See [LICENSE](./LICENSE) for detail.
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fshotastage%2FFileable.swift.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fshotastage%2FFileable.swift?ref=badge_large)

View File

@ -3,7 +3,7 @@
// Fileable // Fileable
// //
// Created by Shota Shimazu on 2017/10/25. // Created by Shota Shimazu on 2017/10/25.
// Copyright © 2017-2020 Shota Shimazu. All rights reserved. // Copyright © 2017-2018 Shota Shimazu. All rights reserved.
// //
import Foundation import Foundation
@ -33,11 +33,6 @@ public enum FileableError: Error {
/// Previous /// Previous
case AleardyExists case AleardyExists
/// Zip
case InvalidZipFile
case ZipCompressFailure
case ZipExtractFailure
/// Default /// Default
case Unkown(String) case Unkown(String)
} }

View File

@ -1,24 +1,14 @@
// //
// FHS.swift // Linux+Fileable.swift
// Fileable // Fileable
// //
// Created by Shota Shimazu on 2017/10/25. // Created by Shota Shimazu on 2017/10/25.
// Copyright © 2017-2020 Shota Shimazu. All rights reserved. // Copyright © 2017-2018 Shota Shimazu. All rights reserved.
// //
import Foundation import Foundation
#if os(Linux) #if os(Linux)
open class FileableLinux {
public static let shared = FileableLinux()
private init() { }
}
public enum UnixFS { public enum UnixFS {
case root case root

View File

@ -3,7 +3,7 @@
// Fileable // Fileable
// //
// Created by Shota Shimazu on 2017/10/25. // Created by Shota Shimazu on 2017/10/25.
// Copyright © 2017-2020 Shota Shimazu. All rights reserved. // Copyright © 2017-2018 Shota Shimazu. All rights reserved.
// //
import Foundation import Foundation
@ -105,18 +105,3 @@ extension Path {
return String(fileName.split(separator: ".").last!) 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
}
}

View File

@ -3,7 +3,7 @@
// Fileable // Fileable
// //
// Created by Shota Shimazu on Oct 25, 2017. // Created by Shota Shimazu on Oct 25, 2017.
// Copyright © 2017-2020 Shota Shimazu. All rights reserved. // Copyright © 2017-2018 Shota Shimazu. All rights reserved.
// //
import Foundation import Foundation
@ -13,45 +13,21 @@ open class Path {
// Path // Path
var path: String var path: String
// Separator
public var separator: String = "/"
// Foundational File Manager // Foundational File Manager
static var fm = FileManager.default 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 // Initializers
public required init() { public init() {
self.path = Path.pwd self.path = Path.pwd
} }
public init<T>(_ path: T) { public init(_ path: String) {
if path == "~" {
let castedPath: String self.path = Path.home
/// Compatible for both String and URL type
if let pathURL: URL = path as? URL {
castedPath = pathURL.path
} else { } else {
castedPath = path as! String self.path = path
}
self.path = castedPath
if castedPath == "~" {
if let range = castedPath.range(of: "~") {
self.path.replaceSubrange(range, with: Path.home)
}
} }
} }
} }

View File

@ -1,23 +0,0 @@
//
// 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

View File

@ -3,14 +3,13 @@
// Fileable // Fileable
// //
// Created by Shota Shimazu on 2017/10/25. // Created by Shota Shimazu on 2017/10/25.
// Copyright © 2017-2020 Shota Shimazu. All rights reserved. // Copyright © 2017-2018 Shota Shimazu. All rights reserved.
// //
import Foundation import Foundation
extension Path { extension Path {
// TODO: Implement cd clousure like Python with statement
public static func cd(_ path: String) throws { public static func cd(_ path: String) throws {
if !Path.fm.changeCurrentDirectoryPath(path) { if !Path.fm.changeCurrentDirectoryPath(path) {
if !Path.fm.fileExists(atPath: path) { if !Path.fm.fileExists(atPath: path) {
@ -20,13 +19,9 @@ extension Path {
} }
} }
} }
public static func mkdir(_ paths: String..., ignoreError: Bool = true) throws { public static func mkdir(_ path: String) throws {
try Path.fm.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
for path in paths {
try Path.fm.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
}
} }
public func rm() throws { public func rm() throws {

View File

@ -1,17 +0,0 @@
//
// 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
}

View File

@ -1,46 +0,0 @@
//
// 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
}
}

View File

@ -1,98 +0,0 @@
//
// 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
}
}
*/

View File

@ -0,0 +1,83 @@
//
// 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

View File

@ -1,59 +0,0 @@
//
// 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
View File

@ -1,37 +1,10 @@
# 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 ## Version 1.0.9
- [ ] Implement Chmod - Implement Chmod
- [x] iOS Directory - iOS Directory
## Version 1.0.8 ## Version 1.0.8
- [x] Implement List Dir - Implement List Dir

View File

@ -1,49 +0,0 @@
//
// 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 { }
}
}

View File

@ -23,32 +23,13 @@ class IOSDirsTest: XCTestCase {
// This is an example of a functional test case. // This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results. // Use XCTAssert and related functions to verify your tests produce the correct results.
let documentDirectory: String = IOSDirs.document.path //let documentDirectory: String = IOSDirs.document.path
let inboxDirectory: String = IOSDirs.inbox.path //let libraryDirectory: String = IOSDirs.library.path
let libraryDirectory: String = IOSDirs.library.path
let cacheDirectory: String = IOSDirs.cache.path
let tmpDirectory: String = IOSDirs.tmp.path
NSLog("LOG: ")
NSLog("LOG: \(documentDirectory)") // NSLog(documentDirectory)
NSLog("LOG: \(inboxDirectory)") // NSLog(libraryDirectory)
NSLog("LOG: \(libraryDirectory)") // XCTAssertEqual(current, moved)
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)
} }