pub fn extract_standalone(
  args: Vec<String>,
) -> Result<Option<(Metadata, String)>, AnyError> {
  let current_exe_path = current_exe()?;

  let mut current_exe = File::open(current_exe_path)?;
  let trailer_pos = current_exe.seek(SeekFrom::End(-24))?;
  let mut trailer = [0; 24];
  current_exe.read_exact(&mut trailer)?;
  let (magic_trailer, rest) = trailer.split_at(8);
  if magic_trailer != MAGIC_TRAILER {
    return Ok(None);
  }

  let (bundle_pos, rest) = rest.split_at(8);
  let metadata_pos = rest;
  let bundle_pos = u64_from_bytes(bundle_pos)?;
  let metadata_pos = u64_from_bytes(metadata_pos)?;
  let bundle_len = metadata_pos - bundle_pos;
  let metadata_len = trailer_pos - metadata_pos;
  current_exe.seek(SeekFrom::Start(bundle_pos))?;

  let bundle = read_string_slice(&mut current_exe, bundle_pos, bundle_len)
    .context("Failed to read source bundle from the current executable")?;
  let metadata =
    read_string_slice(&mut current_exe, metadata_pos, metadata_len)
      .context("Failed to read metadata from the current executable")?;

  let mut metadata: Metadata = serde_json::from_str(&metadata).unwrap();
  metadata.argv.append(&mut args[1..].to_vec());
  Ok(Some((metadata, bundle)))
}
/// This function will try to run this binary as a standalone binary
/// produced by `deno compile`. It determines if this is a standalone
/// binary by checking for the magic trailer string `D3N0` at EOF-12.
/// The magic trailer is followed by:
/// - a u64 pointer to the JS bundle embedded in the binary
/// - a u64 pointer to JSON metadata (serialized flags) embedded in the binary
/// These are dereferenced, and the bundle is executed under the configuration
/// specified by the metadata. If no magic trailer is present, this function
/// exits with `Ok(None)`.
This function will try to run this binary as a standalone binary
produced by `deno compile`. It determines if this is a standalone
binary by checking for the magic trailer string `D3N0` at EOF-12.
The magic trailer is followed by:
a u64 pointer to the JS bundle embedded in the binary
a u64 pointer to JSON metadata (serialized flags) embedded in the binary
These are dereferenced, and the bundle is executed under the configuration
specified by the metadata. If no magic trailer is present, this function
exits with `Ok(None)`.
This function will try to run this binary as a standalone binary produced by ` deno compile ` . It determines if this is a standalone binary by checking for the magic trailer string ` D3N0 ` at EOF - 12 . The magic trailer is followed by : a u64 pointer to the JS bundle embedded in the binary a u64 pointer to JSON metadata ( serialized flags ) embedded in the binary These are dereferenced and the bundle is executed under the configuration specified by the metadata . If no magic trailer is present this function exits with ` Ok ( None ) ` .
pub fn extract_standalone(
  args: Vec<String>,
) -> Result<Option<(Metadata, String)>, AnyError> {
  let current_exe_path = current_exe()?;
  let mut current_exe = File::open(current_exe_path)?;
  let trailer_pos = current_exe.seek(SeekFrom::End(-24))?;
  let mut trailer = [0; 24];
  current_exe.read_exact(&mut trailer)?;
  let (magic_trailer, rest) = trailer.split_at(8);
  if magic_trailer != MAGIC_TRAILER {
    return Ok(None);
  }
  let (bundle_pos, rest) = rest.split_at(8);
  let metadata_pos = rest;
  let bundle_pos = u64_from_bytes(bundle_pos)?;
  let metadata_pos = u64_from_bytes(metadata_pos)?;
  let bundle_len = metadata_pos - bundle_pos;
  let metadata_len = trailer_pos - metadata_pos;
  current_exe.seek(SeekFrom::Start(bundle_pos))?;
  let bundle = read_string_slice(&mut current_exe, bundle_pos, bundle_len)
    .context("Failed to read source bundle from the current executable")?;
  let metadata =
    read_string_slice(&mut current_exe, metadata_pos, metadata_len)
      .context("Failed to read metadata from the current executable")?;
  let mut metadata: Metadata = serde_json::from_str(&metadata).unwrap();
  metadata.argv.append(&mut args[1..].to_vec());
  Ok(Some((metadata, bundle)))
}
pub fn extract_standalone ( args : Vec < String > , ) -> Result < Option < ( Metadata , String ) > , AnyError > { let current_exe_path = current_exe ( ) ? ; let mut current_exe = File :: open ( current_exe_path ) ? ; let trailer_pos = current_exe . seek ( SeekFrom :: End ( - 24 ) ) ? ; let mut trailer = [ 0 ; 24 ] ; current_exe . read_exact ( & mut trailer ) ? ; let ( magic_trailer , rest ) = trailer . split_at ( 8 ) ; if magic_trailer != MAGIC_TRAILER { return Ok ( None ) ; } let ( bundle_pos , rest ) = rest . split_at ( 8 ) ; let metadata_pos = rest ; let bundle_pos = u64_from_bytes ( bundle_pos ) ? ; let metadata_pos = u64_from_bytes ( metadata_pos ) ? ; let bundle_len = metadata_pos - bundle_pos ; let metadata_len = trailer_pos - metadata_pos ; current_exe . seek ( SeekFrom :: Start ( bundle_pos ) ) ? ; let bundle = read_string_slice ( & mut current_exe , bundle_pos , bundle_len ) . context ( " " ) ? ; let metadata = read_string_slice ( & mut current_exe , metadata_pos , metadata_len ) . context ( " " ) ? ; let mut metadata : Metadata = serde_json :: from_str ( & metadata ) . unwrap ( ) ; metadata . argv . append ( & mut args [ 1 .. ] . to_vec ( ) ) ; Ok ( Some ( ( metadata , bundle ) ) ) }
This function will try to run this binary as a standalone binary
produced by `deno compile`.
This function will try to run this binary as a standalone binary produced by ` deno compile ` .
args
Vec<String>
args
Vec<String>