Keine Beschreibung

RNFetchBlobFS.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 * _Nullable outStream;
  32. @property (nonatomic) NSInputStream * _Nullable 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 *) getCacheDir;
  43. + (NSString *) getDocumentDir;
  44. + (NSString *) getDownloadDir;
  45. + (NSString *) getLibraryDir;
  46. + (NSString *) getMainBundleDir;
  47. + (NSString *) getMovieDir;
  48. + (NSString *) getMusicDir;
  49. + (NSString *) getPictureDir;
  50. + (NSString *) getTempPath;
  51. + (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext;
  52. + (NSString *) getPathOfAsset:(NSString *)assetURI;
  53. + (NSString *) getPathForAppGroup:(NSString *)groupName;
  54. + (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * path, ALAssetRepresentation *asset)) onComplete;
  55. // fs methods
  56. + (RNFetchBlobFS *) getFileStreams;
  57. + (BOOL) mkdir:(NSString *) path;
  58. + (void) mkdir:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
  59. + (void) hash:(NSString *)path
  60. algorithm:(NSString *)algorithm
  61. resolver:(RCTPromiseResolveBlock)resolve
  62. rejecter:(RCTPromiseRejectBlock)reject;
  63. + (NSDictionary *) stat:(NSString *) path error:(NSError **) error;
  64. + (void) exists:(NSString *) path callback:(RCTResponseSenderBlock)callback;
  65. + (void) writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
  66. + (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
  67. + (void) readFile:(NSString *)path encoding:(NSString *)encoding onComplete:(void (^)(NSData * content, NSString* code, NSString * errMsg))onComplete;
  68. + (void) readAssetFile:(NSData *)assetUrl completionBlock:(void(^)(NSData * content))completionBlock failBlock:(void(^)(NSError * err))failBlock;
  69. + (void) slice:(NSString *)path
  70. dest:(NSString *)dest
  71. start:(nonnull NSNumber *)start
  72. end:(nonnull NSNumber *)end
  73. encode:(NSString *)encode
  74. resolver:(RCTPromiseResolveBlock)resolve
  75. rejecter:(RCTPromiseRejectBlock)reject;
  76. //+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
  77. + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest;
  78. + (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId bridgeRef:(RCTBridge *)bridgeRef;
  79. + (void) df:(RCTResponseSenderBlock)callback;
  80. // constructor
  81. - (id) init;
  82. - (id)initWithCallback:(RCTResponseSenderBlock)callback;
  83. - (id)initWithBridgeRef:(RCTBridge *)bridgeRef;
  84. // file stream
  85. - (void) openWithDestination;
  86. - (NSString *)openWithPath:(NSString *)destPath encode:(nullable NSString *)encode appendData:(BOOL)append;
  87. // file stream write data
  88. - (void)write:(NSData *) chunk;
  89. - (void)writeEncodeChunk:(NSString *) chunk;
  90. - (void) closeInStream;
  91. - (void) closeOutStream;
  92. - (void) openFile:( NSString * _Nonnull ) uri;
  93. @end
  94. #endif /* RNFetchBlobFS_h */