Skip to content

Commit

Permalink
Remove data_url and data_embedded from lib as suggested in code review
Browse files Browse the repository at this point in the history
  • Loading branch information
awehrfritz committed Feb 15, 2024
1 parent c5e200f commit c2684d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
12 changes: 6 additions & 6 deletions examples/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ fn main() -> std::io::Result<()> {
// Video file
// Downloaded from the Chromium sources at:
// https://github.com/chromium/chromium/blob/main/media/test/data/bear-1280x720.mp4
let file_name = "examples/bear-1280x720.mp4";
// Get the absolute path and file name.
let file_path = std::fs::canonicalize("examples/bear-1280x720.mp4").unwrap();
let file_name = file_path.file_name().unwrap();

if embedded {
// Read video file and add to pdf as embedded file.
let data = std::fs::read(file_name).unwrap();
let data = std::fs::read(&file_path).unwrap();
pdf.embedded_file(video_file_id, &data);
}

Expand All @@ -139,13 +141,11 @@ fn main() -> std::io::Result<()> {
let mut media_clip = rendition.media_clip();
media_clip.subtype(MediaClipType::Data);
if embedded {
media_clip.data_embedded(video_file_id);
media_clip.data().path(Str(file_name.as_encoded_bytes())).embedded_file(video_file_id);
} else {
// Get the absolute path to the video file.
let file_path = std::fs::canonicalize(file_name)?;
// FIXME: Is there a more elegant way to assemble the URL?
let file_url = &[b"file://", file_path.as_os_str().as_encoded_bytes()].concat();
media_clip.data_url(Str(file_url));
media_clip.data().file_system(Name(b"URL")).path(Str(file_url));
}
media_clip.data_type(Str(b"video/mp4"));
media_clip.permissions().temp_file(TempFileType::Access);
Expand Down
18 changes: 0 additions & 18 deletions src/renditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,6 @@ impl<'a> MediaClip<'a> {
self.insert(Name(b"D")).start()
}

/// Writing the `/D` dictionary including the file specification as a link,
/// i.e. an URL, to a given path.
pub fn data_url(&mut self, path: Str) -> &mut Self {
self.data()
.file_system(Name(b"URL"))
.path(path);
self
}

/// Writing the `/D` dictionary including the file specification as
/// embedded file referenced by a given id.
pub fn data_embedded(&mut self, id: Ref) -> &mut Self {
self.data()
.path(Str(b"<embedded file>"))
.embedded_file(id);
self
}

/// Write the `/CT` attribute identifying the type of data in `/D`, i.e. the
/// MIME type.
pub fn data_type(&mut self, tf: Str) -> &mut Self {
Expand Down

0 comments on commit c2684d7

Please sign in to comment.