Skip to content

Commit

Permalink
feat(alpha0010#7): macos support
Browse files Browse the repository at this point in the history
- update podspec to include macos target
- update readme to mention macos support
  • Loading branch information
mateusz1913 committed May 11, 2021
1 parent 9420503 commit c07c47d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,46 @@ const text = await FileSystem.readFile(Dirs.CacheDir + '/test.txt');
- `Dirs.CacheDir`
- `Dirs.DatabaseDir` (Android only)
- `Dirs.DocumentDir`
- `Dirs.LibraryDir` (iOS only)
- `Dirs.LibraryDir` (iOS & MacOS only)
- `Dirs.MainBundleDir`
- `Dirs.SDCardDir` (Android only)
- Prefer `FileSystem.cpExternal()` when possible.

#### Functions.

`FileSystem.appendFile(path: string, data: string, encoding?: 'utf8' | 'base64'): Promise<void>`

- Append content to a file.
- Default encoding of `data` is assumed utf8.

`FileSystem.concatFiles(source: string, target: string): Promise<number>`

- Append a file to another file. Returns number of bytes written.

`FileSystem.cp(source: string, target: string): Promise<void>`

- Copy a file.

`FileSystem.cpAsset(asset: string, target: string, type?: 'asset' | 'resource'): Promise<void>`

- Copy a bundled asset file.
- Default `type` is `asset`. Prefer this when possible.
- `resource` uses the Android `res/` folder, and inherits the associated
naming restrictions.

`FileSystem.cpExternal(source: string, targetName: string, dir: 'audio' | 'downloads' | 'images' | 'video'): Promise<void>`

- Copy a file to an externally controlled location.
- On Android API level < 29, may require permission WRITE_EXTERNAL_STORAGE.
- On iOS, consider using `Dirs.DocumentDir` with `UIFileSharingEnabled`
and `LSSupportsOpeningDocumentsInPlace` enabled.

`FileSystem.df(): Promise<{ internal_free: number, internal_total: number, external_free?: number, external_total?: number }>`

- Check device available space.

`FileSystem.exists(path: string): Promise<boolean>`

- Check if a path exists.

```
Expand All @@ -74,29 +81,37 @@ type FetchResult = {
url: string;
}
```

- Save a network request to a file.

`FilesSystem.getAppGroupDir(groupName: string): Promise<string>`
- Get the directory for your app group (iOS only).

- Get the directory for your app group (iOS & MacOS only).
- App groups are used on iOS/MacOS for storing content, which is shared between apps.
- This is e.g. useful for sharing data between your iOS app and a widget or a watch app.
- This is e.g. useful for sharing data between your iOS/MacOS app and a widget or a watch app.

`FilesSystem.hash(path: string, algorithm: 'MD5' | 'SHA-1' | 'SHA-224' | 'SHA-256' | 'SHA-384' | 'SHA-512'): Promise<string>`

- Hash the file content.

`FilesSystem.isDir(path: string): Promise<boolean>`

- Check if a path is a directory.

`FileSystem.ls(path: string): Promise<string[]>`

- List files in a directory.

`FileSystem.mkdir(path: string): Promise<void>`

- Make a new directory.

`FileSystem.mv(source: string, target: string): Promise<void>`

- Move a file.

`FileSystem.readFile(path: string, encoding?: 'utf8' | 'base64'): Promise<string>`

- Read the content of a file.
- Default encoding of returned string is utf8.

Expand All @@ -111,12 +126,15 @@ type FileStat = {
type: 'directory' | 'file';
}
```

- Read file metadata.

`FileSystem.unlink(path: string): Promise<void>`

- Delete a file.

`FileSystem.writeFile(path: string, data: string, encoding?: 'utf8' | 'base64'): Promise<void>`

- Write content to a file.
- Default encoding of `data` is assumed utf8.

Expand Down
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function App() {
);

const sourcFile =
Platform.OS === 'ios'
Platform.OS === 'ios' || Platform.OS === 'macos'
? `${Dirs.CacheDir}/renamed.txt`
: `file://${Dirs.CacheDir}/renamed.txt`;

Expand Down
2 changes: 1 addition & 1 deletion react-native-file-access.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => "10.0" }
s.platforms = { :ios => "10.0", :osx => "10.10" }
s.source = { :git => "https://github.com/alpha0010/react-native-file-access.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,swift}"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const Dirs: {
/**
* Persistent app internal data.
*
* iOS only.
* iOS & MacOS only.
*/
LibraryDir?: string;

Expand Down
2 changes: 1 addition & 1 deletion src/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type FileAccessType = {
}
): Promise<FetchResult>;
/**
* Only defined on iOS.
* Only defined on iOS & MacOS.
*/
getAppGroupDir(groupName: string): Promise<string>;
hash(path: string, algorithm: HashAlgorithm): Promise<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* asset - Android `assets/` folder or iOS main bundle.
* asset - Android `assets/` folder or iOS/MacOS main bundle.
* resource - Android `res/` folder.
*/
export type AssetType = 'asset' | 'resource';
Expand Down

0 comments on commit c07c47d

Please sign in to comment.