pub async fn dataset_download_file(
        &self,
        name: impl AsRef<str>,
        file_name: impl AsRef<str>,
        folder: Option<PathBuf>,
        dataset_version_number: Option<&str>,
    ) -> anyhow::Result<PathBuf> {
        let (owner_slug, dataset_slug) = self.get_user_and_identifier_slug(name.as_ref())?;

        let mut req = self
            .client
            .get(self.join_url(format!(
                "datasets/download/{}/{}/{}",
                owner_slug,
                dataset_slug,
                file_name.as_ref()
            ))?)
            .header(header::ACCEPT, HeaderValue::from_static("file"));

        if let Some(version) = dataset_version_number {
            req = req.query(&[("datasetVersionNumber", version)]);
        }

        let resp = Self::request(req).await?;

        let url = resp
            .url()
            .path_segments()
            .context("redirected to invalid dataset download url")?
            .last()
            .context("no file segment in url download path")?;

        let output = folder.unwrap_or_else(|| {
            self.download_dir
                .join(format!("datasets/{}/{}", owner_slug, dataset_slug))
        });

        fs::create_dir_all(&output)?;
        let outfile = output.join(url);

        // TODO check if file is already available and is older than the Last-Modified
        // header value
        Ok(Self::write_resp(resp, outfile).await?)
    }
/// Download a single file for a dataset.
Download a single file for a dataset.
Download a single file for a dataset .
pub async fn dataset_download_file(
        &self,
        name: impl AsRef<str>,
        file_name: impl AsRef<str>,
        folder: Option<PathBuf>,
        dataset_version_number: Option<&str>,
    ) -> anyhow::Result<PathBuf> {
        let (owner_slug, dataset_slug) = self.get_user_and_identifier_slug(name.as_ref())?;
        let mut req = self
            .client
            .get(self.join_url(format!(
                "datasets/download/{}/{}/{}",
                owner_slug,
                dataset_slug,
                file_name.as_ref()
            ))?)
            .header(header::ACCEPT, HeaderValue::from_static("file"));
        if let Some(version) = dataset_version_number {
            req = req.query(&[("datasetVersionNumber", version)]);
        }
        let resp = Self::request(req).await?;
        let url = resp
            .url()
            .path_segments()
            .context("redirected to invalid dataset download url")?
            .last()
            .context("no file segment in url download path")?;
        let output = folder.unwrap_or_else(|| {
            self.download_dir
                .join(format!("datasets/{}/{}", owner_slug, dataset_slug))
        });
        fs::create_dir_all(&output)?;
        let outfile = output.join(url);
        // TODO check if file is already available and is older than the Last-Modified
        // header value
        Ok(Self::write_resp(resp, outfile).await?)
    }
pub async fn dataset_download_file ( & self , name : impl AsRef < str > , file_name : impl AsRef < str > , folder : Option < PathBuf > , dataset_version_number : Option < & str > , ) -> anyhow :: Result < PathBuf > { let ( owner_slug , dataset_slug ) = self . get_user_and_identifier_slug ( name . as_ref ( ) ) ? ; let mut req = self . client . get ( self . join_url ( format ! ( " " owner_slug dataset_slug file_name as_ref ( ) ) ) ? ) . header ( header :: ACCEPT , HeaderValue :: from_static ( " " ) ) ; if let Some ( version ) = dataset_version_number { req = req . query ( & [ ( " " , version ) ] ) ; } let resp = Self :: request ( req ) . await ? ; let url = resp . url ( ) . path_segments ( ) . context ( " " ) ? . last ( ) . context ( " " ) ? ; let output = folder . unwrap_or_else ( | | { self . download_dir . join ( format ! ( " " owner_slug dataset_slug ) ) } ) ; fs :: create_dir_all ( & output ) ? ; let outfile = output . join ( url ) ; // TODO check if file is already available and is older than the Last-Modified // header value Ok ( Self :: write_resp ( resp , outfile ) . await ? ) }
Download a single file for a dataset.
Download a single file for a dataset .
&self
name
impl AsRef<str>
file_name
impl AsRef<str>
folder
Option<PathBuf>
dataset_version_number
Option<&str>
&self
name
impl AsRef<str>
file_name
impl AsRef<str>
folder
Option<PathBuf>
dataset_version_number
Option<&str>