-1

I'm trying to store data on a Firebase Database, but I'm worried about running out of space on my current storage plan. Is there a relatively easy way I could compress my data before uploading it to the Database, and then uncompress afterward?

This data would be simple: Strings, Integers, and maybe Doubles. (Using Firebase's JSON style format)

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Eli Front
  • 695
  • 1
  • 8
  • 28
  • 1
    My suggestion is, instead of worrying, do some calculations to see how much data your app will actually use. Doing some quick math using ASCII as a measuring stick since you are storing strings; 1 char = 1 byte. For example if a string has 20000 chars = 20000 bytes. Divide by 1000 result in 20 kb (that's .02 Mb) compared to the maximum size of a string in a single node, which is 10 MB. Firebase Data is UTF-8 encoded, multiply that 20k by 4. So a 20,000 character string takes up 80k. If you are storing massive datasets, then the answer by @frankvanpuffelen is the way to go; Firebase Storage. – Jay Oct 28 '19 at 18:14

1 Answers1

1

Numbers have a fixed size, so there's nothing you can do to compress them while still keeping them as numbers.

The only type you can reasonably compress are probably strings. Any JavaScript string compression library is probably a good place to start, so I recommend having a look at this question: String compression in JavaScript

That said: the size of strings you'd typically store in the database is usually not too big, so the savings may be quite small. If you have significantly sized data, consider if you're not better off storing it in a file in Cloud Storage, and then storing its (much smaller) path in the database.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807