@@ -29,6 +29,7 @@ import { isActionsAssertion } from "./assertions.js";
2929import { CallbackSigner , LocalSigner } from "./Signer.js" ;
3030import { Reader } from "./Reader.js" ;
3131import { Builder } from "./Builder.js" ;
32+ import { loadC2paSettings , resetSettings } from "./Settings.js" ;
3233
3334const tempDir = path . join ( __dirname , "tmp" ) ;
3435
@@ -277,6 +278,81 @@ describe("Builder", () => {
277278 expect ( activeManifest ?. title ) . toBe ( "Test_Manifest" ) ;
278279 } ) ;
279280
281+ it ( "should populate buffer when archiving to buffer" , async ( ) => {
282+ const archive : DestinationBufferAsset = {
283+ buffer : null ,
284+ } ;
285+ await builder . toArchive ( archive ) ;
286+ expect ( archive . buffer ) . not . toBeNull ( ) ;
287+ expect ( archive . buffer ! . length ) . toBeGreaterThan ( 0 ) ;
288+ } ) ;
289+
290+ it ( "should write archive to file" , async ( ) => {
291+ const archivePath = path . join ( tempDir , "archive_file_test.zip" ) ;
292+ const archive = { path : archivePath } ;
293+ await builder . toArchive ( archive ) ;
294+
295+ // Verify file was created and has content
296+ expect ( await fs . pathExists ( archivePath ) ) . toBe ( true ) ;
297+ const stats = await fs . stat ( archivePath ) ;
298+ expect ( stats . size ) . toBeGreaterThan ( 0 ) ;
299+ } ) ;
300+
301+ it ( "should construct reader directly from builder archive buffer" , async ( ) => {
302+ // Enable c2pa archive format
303+ loadC2paSettings (
304+ JSON . stringify ( {
305+ builder : {
306+ generate_c2pa_archive : true ,
307+ } ,
308+ verify : {
309+ verify_after_reading : false ,
310+ } ,
311+ } ) ,
312+ ) ;
313+
314+ try {
315+ // Create a builder
316+ const simpleManifestDefinition = {
317+ claim_generator_info : [
318+ {
319+ name : "c2pa_test" ,
320+ version : "1.0.0" ,
321+ } ,
322+ ] ,
323+ title : "Test_Manifest" ,
324+ format : "image/jpeg" ,
325+ assertions : [ ] ,
326+ resources : { resources : { } } ,
327+ } ;
328+
329+ const testBuilder = Builder . withJson ( simpleManifestDefinition ) ;
330+
331+ // Add an ingredient
332+ await testBuilder . addIngredient ( parent_json , source ) ;
333+
334+ // Create an archive from the builder written to a buffer
335+ const archive : DestinationBufferAsset = {
336+ buffer : null ,
337+ } ;
338+ await testBuilder . toArchive ( archive ) ;
339+
340+ // Verify buffer was populated
341+ expect ( archive . buffer ) . not . toBeNull ( ) ;
342+ expect ( archive . buffer ! . length ) . toBeGreaterThan ( 0 ) ;
343+
344+ // Construct a reader from the builder archive with mime-type "application/c2pa"
345+ const reader = await Reader . fromAsset ( {
346+ buffer : archive . buffer ! as Buffer ,
347+ mimeType : "application/c2pa" ,
348+ } ) ;
349+ expect ( reader ) . not . toBeNull ( ) ;
350+ } finally {
351+ // Reset settings to defaults
352+ resetSettings ( ) ;
353+ }
354+ } ) ;
355+
280356 it ( "should sign data with callback to file" , async ( ) => {
281357 const dest : FileAsset = {
282358 path : path . join ( tempDir , "callback_signed.jpg" ) ,
0 commit comments