bun icon indicating copy to clipboard operation
bun copied to clipboard

`Bun.file` should extend `File` not `Blob`

Open Electroid opened this issue 1 year ago • 5 comments

Electroid avatar Sep 23 '23 19:09 Electroid

Hope some of this can also be addressed.

  • https://github.com/oven-sh/bun/issues/4460#issuecomment-1725323631

jimmywarting avatar Sep 23 '23 21:09 jimmywarting

Is this as simple as just updating the type to extend a File and making sure the name property of the BunFile is non-nullable? I'm new so I'm unsure of the cascading effects., but it seems that File and Blob are basically the same except for that difference.

zg009 avatar Sep 24 '23 01:09 zg009

Neither BunFile or Blob should have a name or lastModified property, they should live on the File class itself.

I think it should look more like this:

class Blob {
  size = 0
  type = ""
  slice() { ... }
  text() { ... }
  arrayBuffer() { ... }
  stream() { ... }
  [Symbol.toStringTag] = "Blob"
}
class File extends Blob { 
  name = ""
  lastModified = 0
  [Symbol.toStringTag] = "File"
}
class BunFile extends File { 
  constructor() {
    this.file = super(...)
  }
  json() { ... }
  exist() { ... }
  writer() { ... }
  formData() { ... }
  slice() { ... } // in case Bun wants to override Blob.slice to return a BunFile instead. 
}

jimmywarting avatar Sep 24 '23 09:09 jimmywarting

bump

jimmywarting avatar Feb 11 '24 16:02 jimmywarting

What is this breaking?

Jarred-Sumner avatar Feb 11 '24 16:02 Jarred-Sumner