Brak opisu

RNFetchBlobFS.h 3.6KB

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