Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Blob.size Browser Inconsistency #7

Description

@Grey41

I have a JavaScript string which consists of 2048 common characters. I use the following Node.js code to find its size in bytes.

Buffer.from("the long string...").length

This returns the number 2048, which happens to be equal to the length of the string. I am using the Node.js function as my benchmark, so I view this as its actual size in bytes.

On the client side, I use Blob to determine the size of the string.

new Blob(["the long string..."], {type: "text/plain"}).size

This should return exactly the same value as the Node.js code. I tested it on a Linux Firefox browser and it returned 2048, which is good. I tested it on a Windows Firefox browser and it returned 2046, which is not what I was hoping for.

I cannot replicate this issue consistently; some strings produce the same result, and others produce conflicting results. This is a problem that needs solving because JS-ByteBase relies on the browser and the server to calculate the size of a project in bytes.

The most obvious way to achieve consistency is to rely on the server to check the size of the project every time. This would be inefficient because the browser has to constantly check the current size of a project while the user is editing it.

How can I consistently get the size in both the server and the browser?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions