d1nch8g
d1nch8g

Reputation: 619

What is the best way to save byte array in flutter's shared preferences?

I have a bunch of byte arrays that I have to save in my flutter application.

At the moment I convert those byte arrays to base64, and saving them as a single line string.

Is there any better way to save bytes using shared preferences lib/some other lib?

Upvotes: 1

Views: 682

Answers (1)

Faruk
Faruk

Reputation: 5831

base64 encode is good start, but it will produce very long string. How about adding additional process by compress those bytes first using gzip, and then save it on local storage using SharedPreference or Hive

import 'dart:convert';

...

final gZipBytes = gzip.encode(bytesArray);
localStorage.save(key, base64.encode(gZipBytes));

Upvotes: 1

Related Questions