package speiger.src.coreengine.assets.parsers;

import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Consumer;

import org.lwjgl.system.MemoryUtil;

import speiger.src.coreengine.assets.base.IAssetParser;

public class NativeMemoryParser implements IAssetParser<ByteBuffer> {
	public static final IAssetParser<ByteBuffer> INSTANCE = new NativeMemoryParser();
	
	@Override
	public ByteBuffer parseAsset(Path path, Consumer<Closeable> autoCloser) throws IOException {
		byte[] data = Files.readAllBytes(path);
		ByteBuffer buffer = MemoryUtil.memAlloc(data.length);
		buffer.put(data);
		buffer.flip();
		return buffer;
	}
}