Nessuna descrizione

RNFetchBlobFS.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 *) 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. + (void) mkdir:(NSString *) path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
  54. + (void) hash:(NSString *)path
  55. algorithm:(NSString *)algorithm
  56. resolver:(RCTPromiseResolveBlock)resolve
  57. rejecter:(RCTPromiseRejectBlock)reject;
  58. + (NSDictionary *) stat:(NSString *) path error:(NSError **) error;
  59. + (void) exists:(NSString *) path callback:(RCTResponseSenderBlock)callback;
  60. + (void) writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
  61. + (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
  62. + (void) readFile:(NSString *)path encoding:(NSString *)encoding onComplete:(void (^)(NSData * content, NSString* code, NSString * errMsg))onComplete;
  63. + (void) readAssetFile:(NSData *)assetUrl completionBlock:(void(^)(NSData * content))completionBlock failBlock:(void(^)(NSError * err))failBlock;
  64. + (void) slice:(NSString *)path
  65. dest:(NSString *)dest
  66. start:(nonnull NSNumber *)start
  67. end:(nonnull NSNumber *)end
  68. encode:(NSString *)encode
  69. resolver:(RCTPromiseResolveBlock)resolve
  70. rejecter:(RCTPromiseRejectBlock)reject;
  71. //+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
  72. + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest;
  73. + (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId bridgeRef:(RCTBridge *)bridgeRef;
  74. + (void) df:(RCTResponseSenderBlock)callback;
  75. // constructor
  76. - (id) init;
  77. - (id)initWithCallback:(RCTResponseSenderBlock)callback;
  78. - (id)initWithBridgeRef:(RCTBridge *)bridgeRef;
  79. // file stream
  80. - (void) openWithDestination;
  81. - (NSString *)openWithPath:(NSString *)destPath encode:(nullable NSString *)encode appendData:(BOOL)append;
  82. // file stream write data
  83. - (void)write:(NSData *) chunk;
  84. - (void)writeEncodeChunk:(NSString *) chunk;
  85. - (void) closeInStream;
  86. - (void) closeOutStream;
  87. - (void) openFile:( NSString * _Nonnull ) uri;
  88. @end
  89. #endif /* RNFetchBlobFS_h */