11// @ts -ignore`
2- import { Buffer } from "buffer" ;
32import { BucketSettings } from "./messages/BucketSettings" ;
43import { BucketInfo } from "./messages/BucketInfo" ;
54import { EntryInfo } from "./messages/EntryInfo" ;
@@ -589,20 +588,20 @@ export class Bucket {
589588 async writeAttachments (
590589 entry : string ,
591590 attachments : Record < string , unknown > ,
592- contentType ?: string ,
593591 ) : Promise < void > {
594- const ct = contentType ?? "application/json" ;
595- const isJson = isJsonContentType ( ct ) ;
596592 const batch = this . beginWriteRecordBatch ( ) ;
597593 const entryName = `${ entry } /$meta` ;
598594 const baseTs = BigInt ( Date . now ( ) ) * 1000n ;
599595 let offset = 0n ;
600596
601597 for ( const [ key , content ] of Object . entries ( attachments ) ) {
602- const data = isJson
603- ? JSON . stringify ( content )
604- : Buffer . from ( content as string , "base64" ) ;
605- batch . add ( entryName , baseTs + offset , data , ct , { key } ) ;
598+ batch . add (
599+ entryName ,
600+ baseTs + offset ,
601+ JSON . stringify ( content ) ,
602+ "application/json" ,
603+ { key } ,
604+ ) ;
606605 offset += 1n ;
607606 }
608607
@@ -625,12 +624,7 @@ export class Bucket {
625624 }
626625
627626 const key = record . labels [ "key" ] . toString ( ) ;
628- if ( isJsonContentType ( record . contentType ?? "" ) ) {
629- attachments [ key ] = JSON . parse ( await record . readAsString ( ) ) ;
630- } else {
631- const buf = await record . read ( ) ;
632- attachments [ key ] = buf . toString ( "base64" ) ;
633- }
627+ attachments [ key ] = JSON . parse ( await record . readAsString ( ) ) ;
634628 }
635629
636630 return attachments ;
@@ -674,10 +668,3 @@ export class Bucket {
674668 await batch . send ( ) ;
675669 }
676670}
677-
678- function isJsonContentType ( contentType : string ) : boolean {
679- const ct = contentType . split ( ";" ) [ 0 ] . trim ( ) . toLowerCase ( ) ;
680- return (
681- ct === "application/json" || ct === "text/json" || ct . endsWith ( "+json" )
682- ) ;
683- }
0 commit comments