-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
464 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Copyright (c) 2024 Mohammad Nejati | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Official repository: https://github.com/cppalliance/http_io | ||
// | ||
|
||
#include "file.hpp" | ||
|
||
#include <boost/http_proto/file.hpp> | ||
#include <boost/system/system_error.hpp> | ||
|
||
namespace http_proto = boost::http_proto; | ||
using system_error = boost::system::system_error; | ||
|
||
std::uint64_t | ||
filesize(const std::string& path) | ||
{ | ||
http_proto::file file; | ||
boost::system::error_code ec; | ||
|
||
file.open(path.c_str(), http_proto::file_mode::scan, ec); | ||
if(ec) | ||
throw system_error{ ec }; | ||
|
||
const auto size = file.size(ec); | ||
if(ec) | ||
throw system_error{ ec }; | ||
|
||
return size; | ||
} | ||
|
||
core::string_view | ||
filename(core::string_view path) noexcept | ||
{ | ||
const auto pos = path.find_last_of("/\\"); | ||
if((pos != core::string_view::npos)) | ||
return path.substr(pos + 1); | ||
return path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright (c) 2024 Mohammad Nejati | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// Official repository: https://github.com/cppalliance/http_io | ||
// | ||
|
||
#ifndef BURL_FILE_HPP | ||
#define BURL_FILE_HPP | ||
|
||
#include <boost/core/detail/string_view.hpp> | ||
|
||
#include <cstdint> | ||
|
||
namespace core = boost::core; | ||
|
||
std::uint64_t | ||
filesize(const std::string& path); | ||
|
||
core::string_view | ||
filename(core::string_view path) noexcept; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.