aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/webcore/blob.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/webcore/blob.zig')
-rw-r--r--src/bun.js/webcore/blob.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index c5e893a5a..604726c1e 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -1233,6 +1233,34 @@ pub const Blob = struct {
return blob_;
}
+ fn estimatedByteSize(this: *Blob) usize {
+ // in-memory size. not the size on disk.
+ if (this.size != Blob.max_size) {
+ return this.size;
+ }
+
+ var store = this.store orelse return 0;
+ if (store.data == .bytes) {
+ return store.data.bytes.len;
+ }
+
+ return 0;
+ }
+
+ pub fn estimatedSize(this: *Blob) callconv(.C) usize {
+ var size = this.estimatedByteSize() + @sizeOf(Blob);
+
+ if (this.store) |store| {
+ size += @sizeOf(Blob.Store);
+ size += switch (store.data) {
+ .bytes => store.data.bytes.stored_name.len,
+ .file => store.data.file.pathlike.path.slice().len,
+ };
+ }
+
+ return size + (this.content_type.len * @as(usize, @intFromBool(this.content_type_allocated)));
+ }
+
comptime {
if (!JSC.is_bindgen) {
_ = JSDOMFile__hasInstance;
span>/+3 2021-11-22remove .thenGravatar Jack Hanford 1-12/+3 2021-11-22another tryGravatar Jack Hanford 2-5/+1 2021-11-22add type fnsGravatar Jack Hanford 1-1/+4