@tishlang/tish 2.1.0 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -666,6 +666,23 @@ pub fn read_file(args: &[Value]) -> Value {
666
666
  }
667
667
  }
668
668
 
669
+ /// Read a file as raw bytes — an array of numbers 0–255 — for binary data that `read_file`
670
+ /// (UTF-8 only) can't handle (images, fonts, archives). Lets pure-Tish decoders work on local
671
+ /// files. See issue #120.
672
+ #[cfg(feature = "fs")]
673
+ pub fn read_file_bytes(args: &[Value]) -> Value {
674
+ let path = args
675
+ .first()
676
+ .map(|v| v.to_display_string())
677
+ .unwrap_or_default();
678
+ match std::fs::read(&path) {
679
+ Ok(bytes) => Value::Array(VmRef::new(
680
+ bytes.into_iter().map(|b| Value::Number(b as f64)).collect(),
681
+ )),
682
+ Err(e) => make_error_value(e),
683
+ }
684
+ }
685
+
669
686
  #[cfg(feature = "fs")]
670
687
  pub fn write_file(args: &[Value]) -> Value {
671
688
  let path = args
@@ -169,6 +169,9 @@ fn get_builtin_export(enabled: &HashSet<String>, spec: &str, export_name: &str)
169
169
  "mkdir" => Some(Value::native(|args: &[Value]| {
170
170
  tishlang_runtime::mkdir(args)
171
171
  })),
172
+ "readFileBytes" => Some(Value::native(|args: &[Value]| {
173
+ tishlang_runtime::read_file_bytes(args)
174
+ })),
172
175
  _ => None,
173
176
  };
174
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tishlang/tish",
3
- "version": "2.1.0",
3
+ "version": "2.2.3",
4
4
  "description": "Tish - minimal TS/JS-compatible language. Run, REPL, build to native or other targets.",
5
5
  "license": "PIF",
6
6
  "repository": {
Binary file
Binary file
Binary file
Binary file
Binary file