RNFetchBlobFS.h
3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// RNFetchBlobFS.h
// RNFetchBlob
//
// Created by Ben Hsieh on 2016/6/6.
// Copyright © 2016年 suzuri04x2. All rights reserved.
//
#ifndef RNFetchBlobFS_h
#define RNFetchBlobFS_h
#import "RNFetchBlob.h"
#import <Foundation/Foundation.h>
#if __has_include(<React/RCTAssert.h>)
#import <React/RCTBridgeModule.h>
#else
#import "RCTBridgeModule.h"
#endif
@import AssetsLibrary;
@interface RNFetchBlobFS : NSObject <NSStreamDelegate> {
NSOutputStream * outStream;
NSInputStream * inStream;
RCTResponseSenderBlock callback;
RCTBridge * bridge;
Boolean isOpen;
NSString * encoding;
int bufferSize;
BOOL appendData;
NSString * taskId;
NSString * path;
NSString * streamId;
}
@property (nonatomic) NSOutputStream * outStream;
@property (nonatomic) NSInputStream * inStream;
@property (strong, nonatomic) RCTResponseSenderBlock callback;
@property (nonatomic) RCTBridge * bridge;
@property (nonatomic) NSString * encoding;
@property (nonatomic) NSString * taskId;
@property (nonatomic) NSString * path;
@property (nonatomic) int bufferSize;
@property (nonatomic) NSString * streamId;
@property (nonatomic) BOOL appendData;
// get dirs
+ (NSString *) getMainBundleDir;
+ (NSString *) getTempPath;
+ (NSString *) getCacheDir;
+ (NSString *) getDocumentDir;
+ (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext;
+ (NSString *) getPathOfAsset:(NSString *)assetURI;
+ (NSString *) getPathForAppGroup:(NSString *)groupName;
+ (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * path, ALAssetRepresentation *asset)) onComplete;
// fs methods
+ (RNFetchBlobFS *) getFileStreams;
+ (BOOL) mkdir:(NSString *) path;
+ (NSDictionary *) stat:(NSString *) path error:(NSError **) error;
+ (void) exists:(NSString *) path callback:(RCTResponseSenderBlock)callback;
+ (void) writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
+ (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
+ (void) readFile:(NSString *)path encoding:(NSString *)encoding onComplete:(void (^)(NSData * content, NSString * errMsg))onComplete;
+ (void) readAssetFile:(NSData *)assetUrl completionBlock:(void(^)(NSData * content))completionBlock failBlock:(void(^)(NSError * err))failBlock;
+ (void) slice:(NSString *)path
dest:(NSString *)dest
start:(nonnull NSNumber *)start
end:(nonnull NSNumber *)end
encode:(NSString *)encode
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject;
//+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
+ (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest;
+ (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId bridgeRef:(RCTBridge *)bridgeRef;
+ (void) df:(RCTResponseSenderBlock)callback;
// constructor
- (id) init;
- (id)initWithCallback:(RCTResponseSenderBlock)callback;
- (id)initWithBridgeRef:(RCTBridge *)bridgeRef;
// file stream
- (void) openWithDestination;
- (NSString *)openWithPath:(NSString *)destPath encode:(nullable NSString *)encode appendData:(BOOL)append;
// file stream write data
- (void)write:(NSData *) chunk;
- (void)writeEncodeChunk:(NSString *) chunk;
- (void) closeInStream;
- (void) closeOutStream;
- (void) openFile:( NSString * _Nonnull ) uri;
@end
#endif /* RNFetchBlobFS_h */