Skip to content
lqez edited this page Feb 5, 2013 · 1 revision

Sample Code in C

Open & read an entity

int teakey[4] = {1,2,3,4};
NPK_PACKAGE pack;
NPK_ENTITY entity;
size_t size;
void* buf;

pack = npk_package_open( "foo.npk", teakey );
entity = npk_package_get_entity( pack, "bar.jpg" );
size = npk_entity_get_size( entity );
buf = malloc( size );
npk_entity_read( entity, buf );
free( buf );
npk_package_close( pack );

Create a new package and add a file

int teakey[4] = {1,2,3,4};
NPK_PACKAGE pack;
NPK_ENTITY entity;

npk_package_alloc( &pack, teakey );
npk_package_add_file( pack, "/tmp/bar.jpg", "bar.jpg", &entity );
npk_package_save( pack, "foo.npk", true );
npk_package_close( pack );

Export an entity into a file

int teakey[4] = {1,2,3,4};
NPK_PACKAGE pack;
NPK_ENTITY entity;

pack = npk_package_open( "foo.npk", teakey );
entity = npk_package_get_entity( pack, "bar.jpg" );
npk_entity_export( entity, "newbar.jpg", true );
npk_package_close( pack );