Skip to content

HW7 is completed#7

Open
ezhk wants to merge 3 commits intomasterfrom
hw07_file_copying
Open

HW7 is completed#7
ezhk wants to merge 3 commits intomasterfrom
hw07_file_copying

Conversation

@ezhk
Copy link
Copy Markdown
Owner

@ezhk ezhk commented Aug 3, 2020

No description provided.

farir1408
farir1408 previously approved these changes Aug 6, 2020
}

fileSize := fileSt.Size()
fmt.Println(fileSize)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отладочный вывод лучше удалить.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо, убрал.

}

func changeZeroLimit(fromPath string, limit int64) int64 {
fileSt, _ := os.Stat(fromPath)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ошибки стоит проверять всегда, это хороший тон.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Согласен, поправил.

return nil
}

func changeZeroLimit(fromPath string, limit int64) int64 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А может ли быть вариант, когда offset + limit > fileSize ? Что тогда делать?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Внутри openLimitedReader есть проверка на offset, а limit не может быть больше FileSize.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit задаётся как внешний параметр, его можно задать и больше чем FileSize, не вижу где в работе проверяется это ограничение.

}

func defineLimitedReader(fromPath string, offset, limit int64) (io.Reader, error) {
reader, err := os.Open(fromPath)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Файлы надо закрывать.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Закрываю в main сам reader.

return err
}

_, err = io.Copy(writer, barReader)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше воспользоваться io.CopyN().

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тогда нужно будет цикл делать?
Я ведь правильно понял, что цель — копировать небольшими «порциями»?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Он внутри копирует порциями.

@farir1408
Copy link
Copy Markdown
Collaborator

Здравствуйте!

Спасибо за выполнение домашнего задания.

Принято 8/10.

return err
}

_, err = io.Copy(writer, barReader)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Он внутри копирует порциями.

return nil
}

func changeZeroLimit(fromPath string, limit int64) int64 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit задаётся как внешний параметр, его можно задать и больше чем FileSize, не вижу где в работе проверяется это ограничение.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants