initialRealmFile

fun initialRealmFile(assetFile: String, sha256checkSum: String? = null): S

Initializes a realm file with a bundled asset realm file.

When opening the realm for the first time the realm file is initialized from the given assetFile. This only happens if the realm files at path not already exists.

The asset file is sought located on the platform's conventional locations for bundled assets/resources:

  • Android: Through android.content.res.AssetManager.open(assetFilename)

  • JVM: Class.javaClass.classLoader.getResource(assetFilename)

  • Darwin: NSBundle.mainBundle.pathForResource(assetFilenameBase, assetFilenameExtension) And it is the responsibility of the developer to place the files at the appropriate location.

This cannot be combined with inMemory or RealmConfiguration.Builder.deleteRealmIfMigrationNeeded. Attempts to do so will cause build to throw an IllegalStateException.

NOTE: This could potentially be a lengthy operation, so opening a Realm with a predefined asset file should ideally be done on a background thread. NOTE: There is currently no protection against multiple processes trying to copy the asset file in place at the same time, so user must ensure that only one process is trying to trigger this at a time.

Parameters

assetFile

the name of the assetFile in the platform's default asset/resource location. If the asset file cannot be located when opening the realm for the first time Realm.open will fail with an IllegalArgumentException.

sha256checkSum

a SHA256-checksum used to verify the integrity of the asset file. If this is specified and the checksum does not match the computed checksum of the assetFile when the realm is opened the first time Realm.open will fail with a IllegalArgumentException.

Throws

if called with an empty assetFile.