l4u / nsdata-base64 Goto Github PK
View Code? Open in Web Editor NEWnot maintained: please use nicklockwood's https://github.com/nicklockwood/Base64
not maintained: please use nicklockwood's https://github.com/nicklockwood/Base64
I added your code to my project but I found this error:
PATH/NSData+Base64.m:293:6: ARC forbids explicit message send of 'autorelease'
I tried to refactor it but no way.
You can use -[NSData initWithBytesNoCopy: length: freeWhenDone:] method to avoid an unneeded memory copy and free(), like the following.
- (id)initWithBase64String:(NSString *)aString
{
NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
size_t outputLength;
void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
return [self initWithBytesNoCopy:outputBuffer length:outputLength freeWhenDone:YES];
}
NSString *dataBaseString = [[@"qwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiop" dataUsingEncoding:NSASCIIStringEncoding] base64EncodedString];
log:
dataBaseString :cXdlcnR5dWlvcHF3ZXJ0eXVpb3Bxd2VydHl1aW9wcXdlcnR5dWlvcHF3ZXJ0eXVp
b3A=
i think it happens because the length of the origin string.
If the input string contains no valid base64 data, this routine will crash. For instance: if the input is a string containing just spaces (and thus no valid base64 data), then NewBase64Decode() returns a valid pointer but an invalid (-1) length. dataFromBase64String() subsequently tries to allocate a NSData block of size (-1), which crashes. This situation should be checked for and handled appropriately.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.