1111#import " ReactNativeBlobUtilFS.h"
1212#import " ReactNativeBlobUtilConst.h"
1313#import " ReactNativeBlobUtilFileTransformer.h"
14- @ import AssetsLibrary;
14+ # import < AssetsLibrary/AssetsLibrary.h >
1515
1616#import < CommonCrypto/CommonDigest.h>
1717
@@ -58,9 +58,9 @@ - (id)initWithCallback:(RCTResponseSenderBlock)callback {
5858 return self;
5959}
6060
61- - (id )initWithBridgeRef : (RCTBridge *)bridgeRef {
61+ - (id )initWithEventDispatcherRef : (RCTEventDispatcher *)eventDispatcherRef {
6262 self = [super init ];
63- self.bridge = bridgeRef ;
63+ self.eventDispatcher = eventDispatcherRef ;
6464 return self;
6565}
6666
@@ -69,7 +69,7 @@ + (NSArray *) getFileStreams {
6969
7070 if (fileStreams == nil )
7171 fileStreams = [[NSMutableDictionary alloc ] init ];
72- return fileStreams;
72+ return fileStreams. allValues ;
7373}
7474
7575+(void ) setFileStream : (ReactNativeBlobUtilFS *) instance withId : (NSString *) uuid {
@@ -160,11 +160,11 @@ + (void) readStream:(NSString *)uri
160160 bufferSize : (int )bufferSize
161161 tick : (int )tick
162162 streamId : (NSString *)streamId
163- bridgeRef : (RCTBridge *)bridgeRef
163+ eventDispatcherRef : (RCTEventDispatcher *)eventDispatcherRef
164164{
165165 [[self class ] getPathFromUri: uri completionHandler: ^(NSString *path, ALAssetRepresentation *asset) {
166166
167- __block RCTEventDispatcher * event = bridgeRef. eventDispatcher ;
167+ __block RCTEventDispatcher * event = eventDispatcherRef ;
168168 __block int read = 0 ;
169169 __block int backoff = tick *1000 ;
170170 __block int chunkSize = bufferSize;
@@ -508,15 +508,16 @@ + (void) readFile:(NSString *)path
508508 __block Byte * buffer;
509509 if (asset != nil )
510510 {
511- buffer = malloc (asset.size );
511+ int size = asset.size ;
512+ buffer = (Byte *)malloc (size);
512513 [asset getBytes: buffer fromOffset: 0 length: asset.size error: &err];
513514 if (err != nil )
514515 {
515516 onComplete (nil , @" EUNSPECIFIED" , [err description ]);
516517 free (buffer);
517518 return ;
518519 }
519- fileContent = [NSData dataWithBytes: buffer length: asset. size];
520+ fileContent = [NSData dataWithBytes: buffer length: size];
520521 free (buffer);
521522 }
522523 else
@@ -555,21 +556,25 @@ + (void) readFile:(NSString *)path
555556 if ([[encoding lowercaseString ] isEqualToString: @" utf8" ])
556557 {
557558 NSString * utf8 = [[NSString alloc ] initWithData: fileContent encoding: NSUTF8StringEncoding];
558- if (utf8 == nil )
559- onComplete ([[NSString alloc ] initWithData: fileContent encoding: NSISOLatin1StringEncoding], nil , nil );
560- else
561- onComplete (utf8, nil , nil );
559+ if (utf8 == nil ) {
560+ NSString * latin1 = [[NSString alloc ] initWithData: fileContent encoding: NSISOLatin1StringEncoding];
561+ NSData * latin1Data = [latin1 dataUsingEncoding: NSISOLatin1StringEncoding];
562+ onComplete (latin1Data, nil , nil );
563+ } else {
564+ onComplete (fileContent, nil , nil );
565+ }
562566 }
563567 else if ([[encoding lowercaseString ] isEqualToString: @" base64" ]) {
564- onComplete ([fileContent base64EncodedStringWithOptions: 0 ], nil , nil );
568+ NSString * base64String = [fileContent base64EncodedStringWithOptions: 0 ];
569+ onComplete ([[NSData alloc ] initWithBase64EncodedString: base64String options: 0 ], nil , nil );
565570 }
566571 else if ([[encoding lowercaseString ] isEqualToString: @" ascii" ]) {
567572 NSMutableArray * resultArray = [NSMutableArray array ];
568- char * bytes = [fileContent bytes ];
573+ char * bytes = ( char *) [fileContent bytes ];
569574 for (int i=0 ;i<[fileContent length ];i++) {
570575 [resultArray addObject: [NSNumber numberWithChar: bytes[i]]];
571576 }
572- onComplete (resultArray, nil , nil );
577+ onComplete (( NSData *) resultArray, nil , nil );
573578 }
574579 }
575580 else
@@ -690,11 +695,11 @@ + (NSDictionary *) stat:(NSString *) path error:(NSError **) error {
690695 if ([fm fileExistsAtPath: path isDirectory: &isDir] == NO ) {
691696 return nil ;
692697 }
693- NSDictionary * info = [fm attributesOfItemAtPath: path error: & error];
694- NSString * size = [NSString stringWithFormat: @" %d " , [info fileSize ]];
698+ NSDictionary * info = [fm attributesOfItemAtPath: path error: error];
699+ NSString * size = [NSString stringWithFormat: @" %llu " , [info fileSize ]];
695700 NSString * filename = [path lastPathComponent ];
696701 NSDate * lastModified;
697- [[NSURL fileURLWithPath: path] getResourceValue: &lastModified forKey: NSURLContentModificationDateKey error: & error];
702+ [[NSURL fileURLWithPath: path] getResourceValue: &lastModified forKey: NSURLContentModificationDateKey error: error];
698703 return @{
699704 @" size" : size,
700705 @" filename" : filename,
@@ -759,7 +764,7 @@ - (void)writeEncodeChunk:(NSString *) chunk {
759764 NSUInteger left = [decodedData length ];
760765 NSUInteger nwr = 0 ;
761766 do {
762- nwr = [self .outStream write: [decodedData bytes ] maxLength: left];
767+ nwr = [self .outStream write: ( const uint8_t *) [decodedData bytes ] maxLength: left];
763768 if (-1 == nwr) break ;
764769 left -= nwr;
765770 } while (left > 0 );
@@ -773,7 +778,7 @@ - (void)write:(NSData *) chunk {
773778 NSUInteger left = [chunk length ];
774779 NSUInteger nwr = 0 ;
775780 do {
776- nwr = [self .outStream write: [chunk bytes ] maxLength: left];
781+ nwr = [self .outStream write: ( const uint8_t *) [chunk bytes ] maxLength: left];
777782 if (-1 == nwr) break ;
778783 left -= nwr;
779784 } while (left > 0 );
@@ -826,7 +831,7 @@ + (void)slice:(NSString *)path
826831 long max = MIN (size, [end longValue ]);
827832
828833 if (![fm fileExistsAtPath: dest]) {
829- if (![fm createFileAtPath: dest contents: @" " attributes: nil ]) {
834+ if (![fm createFileAtPath: dest contents: [ NSData new ] attributes: nil ]) {
830835 return reject (@" ENOENT" , [NSString stringWithFormat: @" File '%@ ' does not exist and could not be created" , path], nil );
831836 }
832837 }
@@ -842,15 +847,15 @@ + (void)slice:(NSString *)path
842847 }
843848 else
844849 {
845- NSLog (@" read chunk %lu " , 10240 );
850+ NSLog (@" read chunk %d " , 10240 );
846851 chunkSize = 10240 ;
847852 chunk = [handle readDataOfLength: 10240 ];
848853 }
849854 if ([chunk length ] <= 0 )
850855 break ;
851856 long remain = expected - read;
852857
853- [os write: [chunk bytes ] maxLength: chunkSize];
858+ [os write: ( const uint8_t *) [chunk bytes ] maxLength: chunkSize];
854859 read += [chunk length ];
855860 }
856861 [handle closeFile ];
@@ -868,19 +873,20 @@ + (void)slice:(NSString *)path
868873 long max = MIN (size, [end longValue ]);
869874
870875 while (read < expected) {
871- uint8_t * chunk[10240 ];
876+ uint8_t chunk[10240 ];
877+ uint8_t * pointerToChunk = &chunk[0 ];
872878 long chunkSize = 0 ;
873879 if ([start longValue ] + read + 10240 > max)
874880 {
875881 NSLog (@" read chunk %lu " , max - read - [start longValue ]);
876882 chunkSize = max - read - [start longValue ];
877- chunkRead = [asset getBytes: chunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
883+ chunkRead = [asset getBytes: pointerToChunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
878884 }
879885 else
880886 {
881887 NSLog (@" read chunk %lu " , 10240 );
882888 chunkSize = 10240 ;
883- chunkRead = [asset getBytes: chunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
889+ chunkRead = [asset getBytes: pointerToChunk fromOffset: [start longValue ] + read length: chunkSize error: nil ];
884890 }
885891 if ( chunkRead <= 0 )
886892 break ;
0 commit comments